diff --git a/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/AnimalLogic.cs b/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/AnimalLogic.cs index 4cd5c9a..f554e86 100644 --- a/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/AnimalLogic.cs +++ b/VeterinaryClinic/VeterinaryClinicBusinessLogics/BusinessLogics/AnimalLogic.cs @@ -71,7 +71,7 @@ namespace VeterinaryClinicBusinessLogics.BusinessLogics public List? ReadList(AnimalSearchModel? model) { - _logger.LogInformation("ReadList. Animal.Id: {Id}. UserId: {DoctorId}", model?.Id, model?.UserId); + _logger.LogInformation("ReadList. Animal.Id: {Id}. UserId: {UserId}", model?.Id, model?.UserId); var list = model == null ? _animalStorage.GetFullList() : _animalStorage.GetFilteredList(model); if (list == null) diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs index 0a018c3..5fc554d 100644 --- a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs @@ -53,18 +53,21 @@ namespace VeterinaryClinicDatabaseImplement.Implements { using var context = new VeterinaryClinicDatabase(); - if (!string.IsNullOrEmpty(model.Breed)) - { - return context.Animals + var filtered = context.Animals .Include(x => x.User) - .Include(x => x.Medications) - .ThenInclude(x => x.Medication) - .Where(x => x.Breed.Contains(model.Breed)) - .Select(x => x.GetViewModel) - .ToList(); - } + .Include(x => x.Medications) + .ThenInclude(x => x.Medication) + .Select(x => x.GetViewModel) + .ToList(); - return new(); + if (model.UserId.HasValue) + { + filtered = filtered + .Where(x => x.UserId.Equals(model.UserId)) + .ToList(); + } + + return filtered ?? new(); } public List GetFullList() @@ -74,7 +77,6 @@ namespace VeterinaryClinicDatabaseImplement.Implements .Include(x => x.User) .Include(x => x.Medications) .ThenInclude(x => x.Medication) - .ToList() .Select(x => x.GetViewModel) .ToList(); } diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs index dd87961..c4943ba 100644 --- a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs @@ -47,10 +47,10 @@ namespace VeterinaryClinicDatabaseImplement.Implements ?.GetViewModel; } - if (!string.IsNullOrEmpty(model.Phone)) + if (!string.IsNullOrEmpty(model.Email)) { return context.Users - .FirstOrDefault(x => x.Phone.Equals(model.Phone)) + .FirstOrDefault(x => x.Email.Equals(model.Email)) ?.GetViewModel; } diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs index 3c3017a..7901d86 100644 --- a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs @@ -58,20 +58,23 @@ namespace VeterinaryClinicDatabaseImplement.Implements { using var database = new VeterinaryClinicDatabase(); - if (!string.IsNullOrEmpty(model.Name)) - { - return database.Vaccinations + var filtered = database.Vaccinations .Include(x => x.User) .Include(x => x.Animal) - .Where(x => x.Name.Contains(model.Name)) .Select(x => x.GetViewModel) .ToList(); - } - return new(); + if (model.UserId.HasValue) + { + filtered = filtered + .Where(x => x.UserId.Equals(model.UserId)) + .ToList(); + } + + return filtered ?? new(); } - public List GetFullList() + public List GetFullList() { using var database = new VeterinaryClinicDatabase(); diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs index 76cae47..5c446cf 100644 --- a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs @@ -33,7 +33,7 @@ namespace VeterinaryClinicDatabaseImplement.Models [ForeignKey("AnimalId")] public virtual List Medications { get; set; } = new(); - private Dictionary? _animalMedications { get; set; } = new(); + private Dictionary? _animalMedications = null; [NotMapped] public Dictionary AnimalMedications { get diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs index e03e2d4..861f9b7 100644 --- a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs @@ -54,6 +54,7 @@ namespace VeterinaryClinicDatabaseImplement.Models Name = model.Name; Cost = model.Cost; + MedicationId = model.MedicationId; } public ServiceViewModel GetViewModel => new() diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs index fe12042..cef6de5 100644 --- a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs @@ -47,6 +47,7 @@ namespace VeterinaryClinicDatabaseImplement.Models Id = model.Id, Name = model.Name, DateInjection = model.DateInjection, + ValidityPeriod = model.ValidityPeriod, UserId = model.UserId, User = context.Users .First(x => x.Id == model.UserId), @@ -65,6 +66,8 @@ namespace VeterinaryClinicDatabaseImplement.Models Name = model.Name; DateInjection = model.DateInjection; + ValidityPeriod = model.ValidityPeriod; + AnimalId = model.AnimalId; } public VaccinationViewModel GetViewModel => new() @@ -72,6 +75,7 @@ namespace VeterinaryClinicDatabaseImplement.Models Id = Id, Name = Name, DateInjection = DateInjection, + ValidityPeriod = ValidityPeriod, UserId = UserId, UserFullName = User.FullName, AnimalId = Animal.Id, diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs index dfb0332..fd6c2db 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs @@ -1,37 +1,142 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using System.Diagnostics; -using VeterinaryClinicWebApp.Models; +using Microsoft.AspNetCore.Mvc; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.BusinessLogicsContracts; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicDataModels.Models; namespace VeterinaryClinicWebApp.Controllers { public class AnimalController : Controller { private readonly ILogger _logger; - public AnimalController(ILogger logger) + + private readonly IAnimalLogic _animalLogic; + + private readonly IMedicationLogic _medicationLogic; + public AnimalController(ILogger logger, IAnimalLogic animalLogic, IMedicationLogic medicationLogic) { _logger = logger; + _animalLogic = animalLogic; + _medicationLogic = medicationLogic; } + /// + /// Вывести список животных + /// + [HttpGet] public IActionResult Animals() { - return View(); + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_animalLogic.ReadList(new AnimalSearchModel + { + UserId = APIClient.User.Id, + })); } + /// + /// Создать животного + /// + [HttpGet] public IActionResult CreateAnimal() { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medications = _medicationLogic.ReadList(null); + return View(); } - public IActionResult UpdateAnimal() + [HttpPost] + public void CreateAnimal(string type, string breed, int age, List medication) { - return View(); + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(breed) || age < 0 || medication == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary animalMedication = new Dictionary(); + foreach (var medicationId in medication) + { + animalMedication.Add(medicationId, _medicationLogic.ReadElement(new MedicationSearchModel { Id = medicationId })!); + } + + _animalLogic.Create(new AnimalBindingModel + { + Type = type, + Breed = breed, + Age = age, + AnimalMedications = animalMedication, + UserId = APIClient.User.Id + }); + + Response.Redirect("/Animal/Animals"); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() + /// + /// Редактировать животного + /// + [HttpGet] + public IActionResult UpdateAnimal(int id) { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medications = _medicationLogic.ReadList(null); + + return View(_animalLogic.ReadElement(new AnimalSearchModel + { + Id = id + })); } + + [HttpPost] + public void UpdateAnimal(int id, string type, string breed, int age, List medication) + { + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(breed) || age < 0 || medication == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary animalMedication = new Dictionary(); + foreach (var medicationId in medication) + { + animalMedication.Add(medicationId, _medicationLogic.ReadElement(new MedicationSearchModel { Id = medicationId })!); + } + + _animalLogic.Update(new AnimalBindingModel + { + Id = id, + Type = type, + Breed = breed, + Age = age, + AnimalMedications = animalMedication, + UserId = APIClient.User.Id + }); + + Response.Redirect("/Animal/Animals"); + } + + /// + /// Удалить животного + /// } } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs index 9010b73..8c5db71 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs @@ -1,5 +1,9 @@ using System.Diagnostics; using Microsoft.AspNetCore.Mvc; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.BusinessLogicsContracts; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicDataModels.Enums; using VeterinaryClinicWebApp.Models; namespace VeterinaryClinicWebApp.Controllers; @@ -8,30 +12,169 @@ public class HomeController : Controller { private readonly ILogger _logger; - public HomeController(ILogger logger) + private readonly IUserLogic _userLogic; + + public HomeController(ILogger logger, IUserLogic userLogic) { _logger = logger; + _userLogic = userLogic; } - public IActionResult Index() + /// + /// + /// + [HttpGet] + public IActionResult Index() { - return View(); - } + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } - public IActionResult Privacy() - { - return View(); - } + return View(APIClient.User); + } - public IActionResult Enter() + /// + /// + /// + [HttpGet] + public IActionResult Privacy() { - return View(); - } - public IActionResult Register() - { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.User); + } + + [HttpPost] + public void Privacy(string fullname, UserRole role, string phone, string email, string password) { + if (APIClient.User == null) + { + throw new Exception(" !"); + } + + if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception(" !"); + } + + _userLogic.Update(new UserBindingModel + { + Id = APIClient.User.Id, + FullName = fullname, + Role = role, + Phone = phone, + Email = email, + Password = password + }); + + APIClient.User.FullName = fullname; + APIClient.User.Role = role; + APIClient.User.Phone = phone; + APIClient.User.Email = email; + APIClient.User.Password = password; + + Response.Redirect("Privacy"); + } + + /// + /// + /// + [HttpGet] + public IActionResult Enter() + { + if (APIClient.User != null) + { + throw new Exception(" !"); + } + return View(); } + [HttpPost] + public void Enter(string email, string password) + { + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception(" !"); + } + + APIClient.User = _userLogic.ReadElement(new UserSearchModel + { + Email = email, + Password = password + }); + if (APIClient.User == null) + { + throw new Exception(" /"); + } + + Response.Redirect("Index"); + } + + /// + /// + /// + [HttpGet] + public IActionResult Register() + { + if (APIClient.User != null) + { + throw new Exception(" !"); + } + + return View(); + } + + [HttpPost] + public void Register(string fullname, UserRole role, string phone, string email, string password) + { + if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception(" !"); + } + + _userLogic.Create(new UserBindingModel + { + FullName = fullname, + Role = role, + Phone = phone, + Email = email, + Password = password + }); + + Response.Redirect("Enter"); + } + + /// + /// + /// + + /// + /// + /// + + /// + /// Word + /// + + /// + /// Excel + /// + + /// + /// Pdf + /// + + /// + /// + /// + + /// + /// + /// [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/MedicationController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/MedicationController.cs index 581010f..dc15948 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/MedicationController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/MedicationController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.BusinessLogicsContracts; +using VeterinaryClinicContracts.SearchModels; using VeterinaryClinicWebApp.Models; namespace VeterinaryClinicWebApp.Controllers @@ -8,20 +11,107 @@ namespace VeterinaryClinicWebApp.Controllers public class MedicationController : Controller { private readonly ILogger _logger; - public MedicationController(ILogger logger) + + private readonly IMedicationLogic _medicationLogic; + public MedicationController(ILogger logger, IMedicationLogic medicationLogic) { _logger = logger; + _medicationLogic = medicationLogic; } + /// + /// Вывести список лекарств + /// public IActionResult Medications() { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_medicationLogic.ReadList(null)); + } + + /// + /// Создать лекарство + /// + /// + [HttpGet] + public IActionResult CreateMedication() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() + [HttpPost] + public void CreateMedication(string name, string description) { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(description)) + { + throw new Exception("Введены не все данные!"); + } + + _medicationLogic.Create(new MedicationBindingModel + { + Name = name, + Description = description + }); + + Response.Redirect("/Medication/Medications"); } + + /// + /// Редактировать лекарство + /// + [HttpGet] + public IActionResult UpdateMedication(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_medicationLogic.ReadElement(new MedicationSearchModel + { + Id = id + })); + } + + [HttpPost] + public void UpdateMedication(int id, string name, string description) + { + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(description)) + { + throw new Exception("Введены не все данные!"); + } + + _medicationLogic.Update(new MedicationBindingModel + { + Id = id, + Name = name, + Description = description + }); + + Response.Redirect("/Medication/Medications"); + } + + /// + /// Удалить лекарство + /// + } } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/ServiceController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/ServiceController.cs index 496416c..849f1ab 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/ServiceController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/ServiceController.cs @@ -1,6 +1,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using VeterinaryClinicBusinessLogics.BusinessLogics; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.BusinessLogicsContracts; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicDataModels.Models; using VeterinaryClinicWebApp.Models; namespace VeterinaryClinicWebApp.Controllers @@ -8,20 +13,115 @@ namespace VeterinaryClinicWebApp.Controllers public class ServiceController : Controller { private readonly ILogger _logger; - public ServiceController(ILogger logger) + + private readonly IServiceLogic _serviceLogic; + + private readonly IMedicationLogic _medicationLogic; + public ServiceController(ILogger logger, IServiceLogic serviceLogic, IMedicationLogic medicationLogic) { _logger = logger; + _serviceLogic = serviceLogic; + _medicationLogic = medicationLogic; } + /// + /// Вывести список животных + /// + [HttpGet] public IActionResult Services() { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_serviceLogic.ReadList(null)); + } + + /// + /// Создать животного + /// + [HttpGet] + public IActionResult CreateService() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medications = _medicationLogic.ReadList(null); + return View(); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() + [HttpPost] + public void CreateService(string name, int cost, int medication) { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || cost <= 0 || medication == 0) + { + throw new Exception("Введены не все данные!"); + } + + _serviceLogic.Create(new ServiceBindingModel + { + Name = name, + Cost = cost, + MedicationId = medication + }); + + Response.Redirect("/Service/Services"); } + + /// + /// Редактировать животного + /// + [HttpGet] + public IActionResult UpdateService(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medications = _medicationLogic.ReadList(null); + + return View(_serviceLogic.ReadElement(new ServiceSearchModel + { + Id = id + })); + } + + [HttpPost] + public void UpdateService(int id, string name, int cost, int medication) + { + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || cost <= 0 || medication == 0) + { + throw new Exception("Введены не все данные!"); + } + + _serviceLogic.Update(new ServiceBindingModel + { + Id = id, + Name = name, + Cost = cost, + MedicationId = medication + }); + + Response.Redirect("/Service/Services"); + } + + /// + /// Удалить животного + /// } } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VaccinationController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VaccinationController.cs index c9c123d..ce904e7 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VaccinationController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VaccinationController.cs @@ -1,6 +1,13 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.Xml.Linq; +using VeterinaryClinicBusinessLogics.BusinessLogics; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.BusinessLogicsContracts; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicDatabaseImplement.Models; +using VeterinaryClinicDataModels.Models; using VeterinaryClinicWebApp.Models; namespace VeterinaryClinicWebApp.Controllers @@ -8,20 +15,127 @@ namespace VeterinaryClinicWebApp.Controllers public class VaccinationController : Controller { private readonly ILogger _logger; - public VaccinationController(ILogger logger) + + private readonly IAnimalLogic _animalLogic; + + private readonly IVaccinationLogic _vaccinationLogic; + public VaccinationController(ILogger logger, IVaccinationLogic vaccinationLogic, IAnimalLogic animalLogic) { _logger = logger; + _vaccinationLogic = vaccinationLogic; + _animalLogic = animalLogic; } + /// + /// Вывести список вакцинаций + /// public IActionResult Vaccinations() { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + return View(_vaccinationLogic.ReadList(new VaccinationSearchModel + { + UserId = APIClient.User.Id, + })); + } + + /// + /// Создать животного + /// + [HttpGet] + public IActionResult CreateVaccination() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Animals = _animalLogic.ReadList(new AnimalSearchModel + { + UserId = APIClient.User.Id, + }); + return View(); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() + [HttpPost] + public void CreateVaccination(string name, DateTime dateInjection, string validityPeriod, int animal) { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || dateInjection == DateTime.MinValue || string.IsNullOrEmpty(validityPeriod) || animal <= 0) + { + throw new Exception("Введены не все данные!"); + } + + _vaccinationLogic.Create(new VaccinationBindingModel + { + Name = name, + DateInjection = dateInjection, + ValidityPeriod = validityPeriod, + AnimalId = animal, + UserId = APIClient.User.Id + }); + + Response.Redirect("/Vaccination/Vaccinations"); } + + /// + /// Редактировать животного + /// + [HttpGet] + public IActionResult UpdateVaccination(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Animals = _animalLogic.ReadList(new AnimalSearchModel + { + UserId = APIClient.User.Id, + }); + + return View(_vaccinationLogic.ReadElement(new VaccinationSearchModel + { + Id = id + })); + } + + [HttpPost] + public void UpdateVaccination(int id, string name, DateTime dateInjection, string validityPeriod, int animal) + { + if (APIClient.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || dateInjection == DateTime.MinValue || string.IsNullOrEmpty(validityPeriod) || animal <= 0) + { + throw new Exception("Введены не все данные!"); + } + + _vaccinationLogic.Update(new VaccinationBindingModel + { + Id = id, + Name = name, + DateInjection = dateInjection, + ValidityPeriod = validityPeriod, + AnimalId = animal, + UserId = APIClient.User.Id + }); + + Response.Redirect("/Vaccination/Vaccinations"); + } + + /// + /// Удалить животного + /// } } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs index f2323cd..1cd6d7b 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs @@ -1,3 +1,7 @@ +using VeterinaryClinicBusinessLogics.BusinessLogics; +using VeterinaryClinicContracts.BusinessLogicsContracts; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicDatabaseImplement.Implements; using VeterinaryClinicWebApp; var builder = WebApplication.CreateBuilder(args); @@ -5,6 +9,29 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +builder.Logging.SetMinimumLevel(LogLevel.Trace); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSession(options => +{ + options.IdleTimeout = TimeSpan.FromMinutes(30); + options.Cookie.HttpOnly = true; + options.Cookie.IsEssential = true; +}); + var app = builder.Build(); APIClient.Connect(builder.Configuration); diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml index 169e056..cf2a27f 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml @@ -31,6 +31,8 @@ Порода Возраст Пользователь + Назначенные лекарства + Действия @@ -38,15 +40,28 @@ @foreach (var animal in Model) { - @Html.DisplayFor(modelItem => animal.Id) - @Html.DisplayFor(modelItem => animal.Type) - @Html.DisplayFor(modelItem => animal.Breed) - @Html.DisplayFor(modelItem => animal.Age) - @Html.DisplayFor(modelItem => animal.UserFullName) + @animal.Id + @animal.Type + @animal.Breed + @animal.Age + @animal.UserFullName + + @if (animal.AnimalMedications.Any()) + { +
    + @foreach (var medication in animal.AnimalMedications) + { +
  • @medication.Value.Name
  • + } +
+ } + else + { +

Нет назначенных лекарств

+ } +

- -

diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/CreateAnimal.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/CreateAnimal.cshtml index 278e32f..329386a 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/CreateAnimal.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/CreateAnimal.cshtml @@ -24,14 +24,14 @@
- +
Медикаменты:
- @foreach (var medication in ViewBag.Medications) { - + }
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/UpdateAnimal.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/UpdateAnimal.cshtml index d04c086..5dd9552 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/UpdateAnimal.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/UpdateAnimal.cshtml @@ -34,13 +34,13 @@
Медикаменты:
- @foreach (var medication in ViewBag.Medications) { var isSelected = Model.AnimalMedications.Any(x => x.Key.Equals(medication.Id)); } - +
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Index.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Index.cshtml index f43ef32..eae9351 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Index.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Index.cshtml @@ -3,5 +3,5 @@ }
-

Welcome to my progect

+

Welcome to my project

diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/CreateMedication.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/CreateMedication.cshtml new file mode 100644 index 0000000..d0654ce --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/CreateMedication.cshtml @@ -0,0 +1,27 @@ +@{ + ViewData["Title"] = "Создание медикамента"; +} + +
+

Создание медикамента

+
+ +
+ +
+
Наименование:
+
+
+ + +
+
Описание:
+
+
+ + +
+
+
+
+
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/Medications.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/Medications.cshtml index 5a3e37d..7472769 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/Medications.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/Medications.cshtml @@ -28,6 +28,7 @@ Номер Название Описание + Действия @@ -40,8 +41,6 @@ @Html.DisplayFor(modelItem => medication.Description)

- -

diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/UpdateMedication.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/UpdateMedication.cshtml new file mode 100644 index 0000000..c52c3ba --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Medication/UpdateMedication.cshtml @@ -0,0 +1,32 @@ + +@using VeterinaryClinicContracts.ViewModels + +@model MedicationViewModel + +@{ + ViewData["Title"] = "Редактирование медикамента"; +} + +
+

Редактирование медикамента

+
+ +
+ +
+
Наименование:
+
+
+ + +
+
Описание:
+
+
+ + +
+
+
+
+
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/CreateService.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/CreateService.cshtml new file mode 100644 index 0000000..88b4995 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/CreateService.cshtml @@ -0,0 +1,40 @@ +@{ + ViewData["Title"] = "Создание услуги"; +} + +
+

Создание услуги

+
+ +
+ +
+
Наименование:
+
+
+ + +
+
Цена:
+
+
+ + +
+
Медикамент:
+
+ +
+
+ + +
+
+
+
+
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/Services.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/Services.cshtml index a4b29dc..dd4de80 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/Services.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/Services.cshtml @@ -29,6 +29,7 @@ Название Цена Медикамент + Действия @@ -42,8 +43,6 @@ @Html.DisplayFor(modelItem => service.MedicationName)

- -

diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/UpdateService.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/UpdateService.cshtml new file mode 100644 index 0000000..cdf0283 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Service/UpdateService.cshtml @@ -0,0 +1,46 @@ + +@using VeterinaryClinicContracts.ViewModels + +@model ServiceViewModel + +@{ + ViewData["Title"] = "Редактирование услуги"; +} + +
+

Редактирование услуги

+
+ +
+ +
+
Наименование:
+
+
+ + +
+
Стоимость:
+
+
+ + +
+
Медикамент:
+
+ +
+
+ + +
+
+
+
+
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Shared/_Layout.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Shared/_Layout.cshtml index f1dce6d..f8d2f87 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Shared/_Layout.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Shared/_Layout.cshtml @@ -11,7 +11,7 @@