diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index d5ba3f9..e62fbd8 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -484,5 +484,107 @@ View(APIPharmacist.GetRequest>($"api/service/getservices? return result; } + public IActionResult Guidances() + { + if (APIPharmacist.Pharmacist == null) + { + return Redirect("~/Home/Enter"); + } + var res = APIPharmacist.GetRequest>($"api/guidance/getguidances"); + return +View(res); + + } + + [HttpGet] + public IActionResult CreateGuidance() + { + ViewBag.Services = APIPharmacist.GetRequest>("api/service/getservices"); + return View(); + } + [HttpPost] + public void CreateGuidance(int service, string text) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(text)) + { + throw new Exception("Рекомендация не может быть пустой"); + } + APIPharmacist.PostRequest("api/guidance/createguidance", new + GuidanceBindingModel + { + ServiceId = service, + Text = text, + }); + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult UpdateGuidance() + { + ViewBag.Services = APIPharmacist.GetRequest>("api/service/getservices"); + ViewBag.Guidances = APIPharmacist.GetRequest>($"api/guidance/getguidances"); + return View(); + } + [HttpPost] + public void UpdateGuidance(int guidance, int service, string text) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(text)) + { + throw new Exception("Рекомендация не может быть пустой"); + } + APIPharmacist.PostRequest("api/guidance/updateguidance", new + GuidanceBindingModel + { + Id = guidance, + ServiceId = service, + Text = text, + }); + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult DeleteGuidance() + { + ViewBag.Guidances = APIPharmacist.GetRequest>($"api/guidance/getguidances"); + return View(); + } + + [HttpPost] + public void DeleteGuidance(int guidance, int service, string text) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIPharmacist.PostRequest("api/guidance/deleteguidance", new + GuidanceBindingModel + { + Id = guidance + }); + Response.Redirect("Index"); + } + + [HttpGet] + public GuidanceViewModel GetGuidance(int guidanceId) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + var result = APIPharmacist.GetRequest($"api/guidance/getguidance?guidanceid={guidanceId}"); + if (result == null) + { + return default; + } + + return result; + } } } diff --git a/VetClinic/PharmacistApp/Views/Home/CreateGuidance.cshtml b/VetClinic/PharmacistApp/Views/Home/CreateGuidance.cshtml new file mode 100644 index 0000000..aa5a6db --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/CreateGuidance.cshtml @@ -0,0 +1,29 @@ +@{ + ViewData["Title"] = "CreateGuidance"; +} + +
+

Создание рекомендации

+
+
+
+
Услуга:
+
+ +
+
+
+
Текст:
+
+ +
+
+
+
+
+ +
+
+
diff --git a/VetClinic/PharmacistApp/Views/Home/DeleteGuidance.cshtml b/VetClinic/PharmacistApp/Views/Home/DeleteGuidance.cshtml new file mode 100644 index 0000000..5721d3b --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/DeleteGuidance.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "DeleteGuidance"; +} +
+

Удаление рекомендации

+
+
+
+
Рекомендация:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Home/Guidances.cshtml b/VetClinic/PharmacistApp/Views/Home/Guidances.cshtml new file mode 100644 index 0000000..c30d534 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/Guidances.cshtml @@ -0,0 +1,56 @@ +@using VetClinicContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Guidances"; +} +
+

Рекомендации

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать рекомендацию + Обновить рекомендацию + Удалить рекомендацию +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Дата + + Текст +
+ @Html.DisplayFor(modelItem => + item.Id) + + @Html.DisplayFor(modelItem => + item.Date) + + @Html.DisplayFor(modelItem => + item.Text) +
+ } +
\ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Home/UpdateGuidance.cshtml b/VetClinic/PharmacistApp/Views/Home/UpdateGuidance.cshtml new file mode 100644 index 0000000..49ff979 --- /dev/null +++ b/VetClinic/PharmacistApp/Views/Home/UpdateGuidance.cshtml @@ -0,0 +1,59 @@ +@{ + ViewData["Title"] = "UpdateGuidance"; +} + +
+

Обновление заказа

+
+
+
+
Рекомендация:
+
+ +
+
+
+
Услуга:
+
+ +
+
+
+
Текст:
+
+ +
+
+
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml b/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml index 002d16d..fde4176 100644 --- a/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml +++ b/VetClinic/PharmacistApp/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - IceCreamShopClientApp + @ViewData["Title"] - PharmacistApp @@ -26,6 +26,9 @@ + @@ -47,7 +50,7 @@ diff --git a/VetClinic/VetClinicContracts/BindingModels/GuidanceBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/GuidanceBindingModel.cs index bcb0639..06903b1 100644 --- a/VetClinic/VetClinicContracts/BindingModels/GuidanceBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/GuidanceBindingModel.cs @@ -11,7 +11,7 @@ namespace VetClinicContracts.BindingModels { public int Id { get; set; } public string Text { get; set; } = string.Empty; - public DateTime Date { get; set; } + public DateTime Date { get; set; } = DateTime.Now; public int ServiceId { get; set; } } } diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/GuidanceStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/GuidanceStorage.cs index 19fbcdf..c0d6e60 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/GuidanceStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/GuidanceStorage.cs @@ -51,16 +51,15 @@ namespace VetClinicDataBaseImplement.Implements public GuidanceViewModel? Update(GuidanceBindingModel model) { using var context = new VetClinicDatabase(); - var element = context.Guidances - .Include(x => x.Service) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) + var order = context.Guidances.Include(x => x.Service).FirstOrDefault(x => x.Id == + model.Id); + if (order == null) { - context.Guidances.Remove(element); - context.SaveChanges(); - return element.GetViewModel; + return null; } - return null; + order.Update(model); + context.SaveChanges(); + return order.GetViewModel; } public GuidanceViewModel? Delete(GuidanceBindingModel model) { diff --git a/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs b/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs index b091edb..9259487 100644 --- a/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs @@ -21,12 +21,29 @@ namespace VetClinicRestApi.Controllers _logger = logger; _guidance = guidance; } - [HttpGet] - public List? GetGuidances(int serviceId) + public GuidanceViewModel GetGuidance(int guidanceId) { try { + var elem = _guidance.ReadElement(new GuidanceSearchModel { Id = guidanceId }); + if (elem == null) + return null; + return elem; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения рекомендации по id={Id}", guidanceId); + throw; + } + } + [HttpGet] + public List? GetGuidances(int? serviceId = null) + { + try + { + if (!serviceId.HasValue) + return _guidance.ReadList(null); return _guidance.ReadList(new GuidanceSearchModel { ServiceId = serviceId diff --git a/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs b/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs index bdc2915..452a64f 100644 --- a/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/MedicineController.cs @@ -4,6 +4,7 @@ using VetClinicContracts.BindingModels; using VetClinicContracts.BusinessLogicsContracts; using VetClinicContracts.SearchModels; using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Models; namespace VetClinicRestApi.Controllers { @@ -42,7 +43,11 @@ namespace VetClinicRestApi.Controllers { try { - var res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId }); + List res; + if (!pharmacistId.HasValue) + res = _medicine.ReadList(null); + else + res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId }); foreach (var medicine in res) medicine.MedicineAnimals = null; return res; diff --git a/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs b/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs index 4109232..a014296 100644 --- a/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs @@ -43,7 +43,11 @@ namespace VetClinicRestApi.Controllers { try { - var res = _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId }); + List res; + if (!pharmacistId.HasValue) + res = _service.ReadList(null); + else + res = _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId }); foreach (var service in res) service.ServiceMedicines = null; return res;