diff --git a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs index 8437f2a..b1ce06e 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToWordDoctor.cs @@ -15,8 +15,8 @@ namespace VeterinaryBusinessLogic.OfficePackage.Implements { private WordprocessingDocument? _wordDocument; private Body? _docBody; - private static JustificationValues - GetJustificationValues(WordJustificationType type) + // получение типов выравнивания + private static JustificationValues GetJustificationValues(WordJustificationType type) { return type switch { @@ -25,6 +25,7 @@ namespace VeterinaryBusinessLogic.OfficePackage.Implements _ => JustificationValues.Left, }; } + // настройки страницы private static SectionProperties CreateSectionProperties() { var properties = new SectionProperties(); @@ -35,9 +36,8 @@ namespace VeterinaryBusinessLogic.OfficePackage.Implements properties.AppendChild(pageSize); return properties; } - - private static ParagraphProperties? - CreateParagraphProperties(WordTextProperties? paragraphProperties) + // задание форматирования для абзаца + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) { if (paragraphProperties == null) { diff --git a/VeterinaryView/VeterinaryDataModels/Models/IServiceModel.cs b/VeterinaryView/VeterinaryDataModels/Models/IServiceModel.cs index b81d74a..d56baa0 100644 --- a/VeterinaryView/VeterinaryDataModels/Models/IServiceModel.cs +++ b/VeterinaryView/VeterinaryDataModels/Models/IServiceModel.cs @@ -11,6 +11,6 @@ namespace VeterinaryDataModels.Models string ServiceName { get; } int VisitId { get; } int DoctorId { get; } - Dictionary ServiceMedications { get; } + Dictionary ServiceMedications { get; } } } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs index db165ab..66df2f4 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/DrugStorage.cs @@ -78,9 +78,10 @@ namespace VeterinaryDatabaseImplement.Implements { return null; } - drug.Update(model); - context.SaveChanges(); + drug.UpdateMedications(context, model); + context.SaveChanges(); + drug.Update(context,model); transaction.Commit(); return drug.GetViewModel; } diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs index 793fda7..9ca3629 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/Drug.cs @@ -68,10 +68,19 @@ namespace VeterinaryDatabaseImplement.Models DateCreate= model.DateCreate }; } - public void Update(DrugBindingModel model) + public void Update(VeterinaryDatabase context, DrugBindingModel model) { + var justMedications = model.DrugMedications.Select(x => new DrugMedication + { + Medication = context.Medications.First(y => y.Id == x.Key) + }).ToList(); + double prc = 0; + foreach (var justMedication in justMedications) + { + prc += justMedication.Medication.Price; + } DrugName = model.DrugName; - Price = model.Price; + Price = prc; } public DrugViewModel GetViewModel => new() { @@ -87,17 +96,24 @@ namespace VeterinaryDatabaseImplement.Models var drugMedications = context.DrugMedications.Where(rec => rec.DrugId == model.Id).ToList(); if (drugMedications != null && drugMedications.Count > 0) { + // из таблицы бд удаляем строчки, которые были отменены(которые раньше были а тепперь их в модели нет) context.DrugMedications.RemoveRange(drugMedications.Where(rec => !model.DrugMedications.ContainsKey(rec.MedicationId))); + // сохраняемся context.SaveChanges(); + foreach (var updateMedication in drugMedications) { + // из модели убираем то что осталось( но зачем?) model.DrugMedications.Remove(updateMedication.MedicationId); } + // сохраняемся context.SaveChanges(); } + // собственно говоря, драг с которым мы работаем var drug = context.Drugs.First(x => x.Id == Id); foreach (var pc in model.DrugMedications) { + // в бдшку добавляем строчки которые остались context.DrugMedications.Add(new DrugMedication { Drug = drug, @@ -106,6 +122,7 @@ namespace VeterinaryDatabaseImplement.Models context.SaveChanges(); } _drugMedications = null; + } } diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs index 1378f1d..61c1cad 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs @@ -18,7 +18,6 @@ namespace VeterinaryRestApi.Controllers _logger = logger; _drug = drug; } - // naher ya eto pisal [HttpGet] public Tuple>? GetDrug(int drugId) { @@ -27,11 +26,13 @@ namespace VeterinaryRestApi.Controllers var elem = _drug.ReadElement(new DrugSearchModel { Id = drugId }); if (elem == null) return null; - return Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList()); + var huinya = Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList()); + return huinya; + //return Tuple.Create(elem, elem.DrugMedications.Select(x => x.Value.MedicationName).ToList()); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения услуги по id={Id}", drugId); + _logger.LogError(ex, "Ошибка получения лекарства по id={Id}", drugId); throw; } } @@ -47,7 +48,7 @@ namespace VeterinaryRestApi.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения продукта по id={Id}",drugId); + _logger.LogError(ex, "Ошибка получения лекарства по id={Id}",drugId); throw; } } @@ -97,7 +98,7 @@ namespace VeterinaryRestApi.Controllers { try { - model.DrugMedications = null!; + //model.DrugMedications = null!; return _drug.Update(model); } catch (Exception ex) diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs index 64d4e75..1caf748 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs @@ -3,6 +3,7 @@ using VeterinaryContracts.BindingModels; using VeterinaryContracts.BusinessLogicContracts; using VeterinaryContracts.SearchModels; using VeterinaryContracts.ViewModels; +using VeterinaryDatabaseImplement.Models; namespace VeterinaryRestApi.Controllers { @@ -17,7 +18,22 @@ namespace VeterinaryRestApi.Controllers _logger = logger; _medication = medication; } - + [HttpGet] + public MedicationViewModel? GetMedication(int medicationId) + { + try + { + return _medication.ReadElement(new MedicationSearchModel + { + Id = medicationId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения медикамента по id={Id}", medicationId); + throw; + } + } [HttpGet] public List GetMedications(int doctorId) { diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs index 89bb157..6acbfe4 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowDoctorApp/Controllers/HomeController.cs @@ -107,6 +107,20 @@ namespace VeterinaryShowDoctorApp.Controllers return; } // medications + [HttpGet] + public MedicationViewModel? GetMedication(int medicationId) + { + if (APIDoctor.Doctor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + var result = APIDoctor.GetRequest ($"api/medication/getmedication?medicationid={medicationId}"); + if (result == null) + { + return default; + } + return result; + } public IActionResult CreateMedication() { if (APIDoctor.Doctor == null) @@ -222,9 +236,6 @@ namespace VeterinaryShowDoctorApp.Controllers Dictionary a = new Dictionary(); foreach (int medication in medications) { - var yeah = new MedicationSearchModel { Id = medication } ; - IMedicationModel tmp = yeah as IMedicationModel; - // фигачит нулл в значение a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel); } APIDoctor.PostRequest("api/drug/createdrug", new DrugBindingModel @@ -233,7 +244,8 @@ namespace VeterinaryShowDoctorApp.Controllers Price = 0, DrugMedications = a, Count = count, - DoctorId = APIDoctor.Doctor.Id + DoctorId = APIDoctor.Doctor.Id, + DateCreate = DateTime.Now, }); Response.Redirect("Drugs"); } @@ -269,7 +281,7 @@ namespace VeterinaryShowDoctorApp.Controllers return Redirect("~/Home/Enter"); } ViewBag.Drugs = APIDoctor.GetRequest>($"api/drug/getdrugs?doctorid={APIDoctor.Doctor.Id}"); - ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications"); + ViewBag.Medications = APIDoctor.GetRequest>($"api/medication/getmedications?doctorid={APIDoctor.Doctor.Id}"); return View(); } @@ -290,15 +302,11 @@ namespace VeterinaryShowDoctorApp.Controllers { a.Add(medication, new MedicationSearchModel { Id = medication } as IMedicationModel); } - foreach (var elem in a) - { - _price += elem.Value.Price; - } APIDoctor.PostRequest("api/drug/updatedrug", new DrugBindingModel { Id = drug, DrugName = name, - Price = Math.Round(_price, 2), + Price = 0, DrugMedications = a, Count = count }); diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml index 0fa3c06..6132adf 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml @@ -20,7 +20,7 @@
Цена:
-
+
@@ -41,8 +41,8 @@ url: "/Home/GetMedication", data: { medicationId: medication }, success: function (result) { - $('#name').val(result.item1.medicationName); - $('#price').val(result.item1.price); + $('#name').val(result.medicationName); + $('#price').val(result.price); } }); };