diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index 402d216..1f6273d 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using VetClinicContracts.BindingModels; using VetClinicContracts.ViewModels; using VetClinicDataBaseImplement.Models; +using VetClinicDataModels.Models; namespace PharmacistApp.Controllers { @@ -175,7 +176,8 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin } [HttpPost] - public void UpdateMedicine(int medicine, string name, int price) + public void UpdateMedicine(int medicine, string name, int price, + Dictionary medicineAnimals = null) { if (APIPharmacist.Pharmacist == null) { @@ -190,7 +192,8 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin Id = medicine, MedicineName = name, Price = price, - PharmacistId = APIPharmacist.Pharmacist.Id + PharmacistId = APIPharmacist.Pharmacist.Id, + MedicineAnimals = medicineAnimals }); Response.Redirect("Index"); } @@ -224,5 +227,16 @@ View(APIPharmacist.GetRequest>($"api/medicine/getmedicin } return Tuple.Create(result.Item1, table); } + + [HttpGet] + public AnimalViewModel? GetAnimal(int animalId) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception(" ? "); + } + var result = APIPharmacist.GetRequest($"api/animal/getanimal?animalid={animalId}"); + return result; + } } } diff --git a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml index 914c29c..b389ecb 100644 --- a/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/UpdateMedicine.cshtml @@ -13,6 +13,9 @@
+
+ +
Название:
diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs index 19a6bb0..64cd951 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/ServiceStorage.cs @@ -31,8 +31,8 @@ namespace VetClinicDataBaseImplement.Implements return context.Services.Include(x => x.Pharmacist) .Include(x => x.Medicines) .ThenInclude(x => x.Medicine) - .Where(x => (string.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName) - && (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId))) + .Where(x => (string.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName)) + && (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -72,7 +72,8 @@ namespace VetClinicDataBaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var iceCream = context.Services.FirstOrDefault(rec => + var iceCream = context.Services.Include(x => x.Pharmacist) + .Include(x => x.Medicines).ThenInclude(x => x.Medicine).FirstOrDefault(rec => rec.Id == model.Id); if (iceCream == null) { @@ -93,10 +94,9 @@ namespace VetClinicDataBaseImplement.Implements public ServiceViewModel? Delete(ServiceBindingModel model) { using var context = new VetClinicDatabase(); - var element = context.Services + var element = context.Services.Include(x => x.Pharmacist) .Include(x => x.Medicines) .ThenInclude(x => x.Medicine) - .ThenInclude(x => x.Animals).ThenInclude(x => x.Animal) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs b/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs new file mode 100644 index 0000000..b091edb --- /dev/null +++ b/VetClinic/VetClinicRestApi/Controllers/GuidanceController.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; +using VetClinicContracts.SearchModels; +using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Models; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class GuidanceController : ControllerBase + { + private readonly ILogger _logger; + private readonly IGuidanceLogic _guidance; + + public GuidanceController(ILogger logger, + IGuidanceLogic guidance) + { + _logger = logger; + _guidance = guidance; + } + + [HttpGet] + public List? GetGuidances(int serviceId) + { + try + { + return _guidance.ReadList(new GuidanceSearchModel + { + ServiceId = serviceId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка рекомендааций услуги id ={ Id}", serviceId); + throw; + } + } + + [HttpPost] + public void CreateGuidance(GuidanceBindingModel model) + { + try + { + _guidance.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания рекомендации"); + throw; + } + } + + [HttpPost] + public bool UpdateGuidance(GuidanceBindingModel model) + { + try + { + return _guidance.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить рекомендацию"); + throw; + } + } + + [HttpPost] + public bool DeleteGuidance(GuidanceBindingModel model) + { + try + { + return _guidance.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления рекомендации"); + throw; + } + } + } +} diff --git a/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs b/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs new file mode 100644 index 0000000..ee36390 --- /dev/null +++ b/VetClinic/VetClinicRestApi/Controllers/ServiceController.cs @@ -0,0 +1,96 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; +using VetClinicContracts.SearchModels; +using VetClinicContracts.ViewModels; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ServiceController : Controller + { + private readonly ILogger _logger; + private readonly IServiceLogic _service; + public ServiceController(ILogger logger, IServiceLogic service) + { + _logger = logger; + _service = service; + } + + [HttpGet] + public Tuple>>? GetService(int serviceId) + { + try + { + var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId }); + if (elem == null) + return null; + return Tuple.Create(elem, elem.ServiceMedicines.Select(x => Tuple.Create(x.Value.Item1.MedicineName, x.Value.Item2)).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения услуги по id={Id}", serviceId); + throw; + } + } + [HttpGet] + public List GetServices(int pharmacistId) + { + try + { + return _service.ReadList(new ServiceSearchModel { PharmacistId = pharmacistId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка услуг"); + throw; + } + } + [HttpPost] + public bool CreateService(ServiceBindingModel model) + { + try + { + return _service.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать услугу"); + throw; + } + } + + [HttpPost] + public bool UpdateService(ServiceBindingModel model) + { + try + { + model.ServiceMedicines = null!; + return _service.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить услугу"); + throw; + } + } + + [HttpPost] + public bool DeleteService(ServiceBindingModel model) + { + try + { + return _service.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления услуги"); + throw; + } + } + + + } +}