diff --git a/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs b/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs index b07b269..aff98fe 100644 --- a/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs +++ b/VetClinic/VetClinicAdminApi/Controllers/HomeController.cs @@ -1,152 +1,226 @@ +using Microsoft.AspNetCore.Mvc; using VetClinicAdminApp.Models; +using System.Diagnostics; using VetClinicContracts.BindingModels; using VetClinicContracts.ViewModels; -using Microsoft.AspNetCore.Mvc; -using System.Diagnostics; namespace VetClinicAdminApp.Controllers { - public class HomeController : Controller - { - private readonly ILogger _logger; + public class HomeController : Controller + { + private readonly ILogger _logger; - public HomeController(ILogger logger) - { - _logger = logger; - } + public HomeController(ILogger logger) + { + _logger = logger; + } - public IActionResult Index() - { - if (APIAdmin.Admin == null) - { - return Redirect("~/Home/Enter"); - } + public IActionResult Index() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + return +View(APIAdmin.GetRequest>($"api/visit/getvisits?vistId={APIAdmin.Admin.Id}")); - return View(APIAdmin.GetRequest>($"api/main/getorders?visitId={APIAdmin.Admin.Id}")); - } + } - [HttpGet] - public IActionResult Privacy() - { - if (APIAdmin.Admin == null) - { - return Redirect("~/Home/Enter"); - } + [HttpGet] + public IActionResult Privacy() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIAdmin.Admin); + } - return View(APIAdmin.Admin); - } + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Ââåäèòå email, ïàðîëü è ÔÈÎ"); + } + APIAdmin.PostRequest("api/admin/updatedata", new + AdminBindingModel + { + Id = APIAdmin.Admin.Id, + AdminFIO = fio, + Email = login, + Password = password + }); + APIAdmin.Admin.AdminFIO = fio; + APIAdmin.Admin.Email = login; + APIAdmin.Admin.Password = password; + Response.Redirect("Index"); + } - [HttpPost] - public void Privacy(string login, string password, string fio) - { - if (APIAdmin.Admin == null) - { - throw new Exception(" ? "); - } + [HttpGet] + public IActionResult Enter() + { + return View(); + } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password)) + { + throw new Exception("Ââåäèòå email è ïàðîëü"); + } + APIAdmin.Admin = + APIAdmin.GetRequest($"api/admin/login?login={login}&password={password}"); + if (APIAdmin.Admin == null) + { + throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü"); + } + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Register() + { + return View(); + } + [HttpPost] + public void Register(string login, string password, string fio) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ"); + } + APIAdmin.PostRequest("api/admin/register", new + AdminBindingModel + { + AdminFIO = fio, + Email = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception(" , "); - } + public IActionResult Create() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } - APIAdmin.PostRequest("api/admin/updatedata", new AdminBindingModel - { - Id = APIAdmin.Admin.Id, - AdminFIO = fio, - Email = login, - Password = password - }); - APIAdmin.Admin.AdminFIO = fio; - APIAdmin.Admin.Email = login; - APIAdmin.Admin.Password = password; - Response.Redirect("Index"); - } + [HttpPost] + public void CreateVisit(string name, DateTime visitdate) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + } + APIAdmin.PostRequest("api/visit/createvisit", new VisitBindingModel + { + NameVisit = name, + DateVisit = visitdate, + AdminId = APIAdmin.Admin.Id + }); + Response.Redirect("Index"); + } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier - }); - } + public IActionResult DeleteMedicine() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Visits = APIAdmin.GetRequest>("api/visit/getvisits"); + return View(); + } - [HttpGet] - public IActionResult Enter() - { - return View(); - } + [HttpPost] + public void DeleteVisit(int shop) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + APIAdmin.PostRequest("api/visit/deletevisit", new VisitBindingModel + { + Id = shop + }); + Response.Redirect("Index"); + } - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { - throw new Exception(" "); - } + public IActionResult Update() + { + if (APIAdmin.Admin == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Medicines = APIAdmin.GetRequest>("api/shop/getvisits"); + return View(); + } - APIAdmin.Admin = APIAdmin.GetRequest($"api/admin/login?login={login}&password={password}"); + [HttpPost] + public void Update(int visit, string name, DateTime vistdate) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + if (string.IsNullOrEmpty(name) ) + { + throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ"); + } + APIAdmin.PostRequest("api/visit/updatevisit", new VisitBindingModel + { + Id = visit, + NameVisit = name, + DateVisit = vistdate, + }); + Response.Redirect("Index"); + } - if (APIAdmin.Admin == null) - { - throw new Exception(" /"); - } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } - Response.Redirect("Index"); - } - - [HttpGet] - public IActionResult Register() - { - return View(); - } - - [HttpPost] - public void Register(string login, string password, string fio) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception(" , "); - } - - APIAdmin.PostRequest("api/admin/register", new AdminBindingModel - { - AdminFIO = fio, - Email = login, - Password = password - }); - - Response.Redirect("Enter"); - - return; - } - - // [HttpGet] - // public IActionResult Create() - // { - // ViewBag.Snacks = APIAdmin.GetRequest>("api/main/getanimallist"); - - // return View(); - // } - - [HttpPost] - public void Create(int animal) - { - if (APIAdmin.Admin == null) - { - throw new Exception(" ? "); - } - - //APIAdmin.PostRequest("api/main/createorder", new VisitBindingModel - //{ - // AdminId = APIAdmin.Admin.Id, - // AnimalId = animal, - // }); - - Response.Redirect("Index"); - } - } -} \ No newline at end of file + [HttpGet] + public Tuple? GetMedicine(int visitId) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); + } + var result = APIAdmin.GetRequest>>($"api/visit/getvisit?visitid={visitId}"); + if (result == null) + { + return default; + } + string table = ""; + result.Item1.VisitAnimals.Clear(); + for (int i = 0; i < result.Item2.Count; i++) + { + var animal = result.Item2[i]; + table += ""; + table += $"{animal}"; + table += ""; + } + return Tuple.Create(result.Item1, table); + } + } +} diff --git a/VetClinic/VetClinicAdminApi/VetClinicAdminApp.csproj b/VetClinic/VetClinicAdminApi/VetClinicAdminApp.csproj index ed11aff..779cc0e 100644 --- a/VetClinic/VetClinicAdminApi/VetClinicAdminApp.csproj +++ b/VetClinic/VetClinicAdminApi/VetClinicAdminApp.csproj @@ -16,7 +16,6 @@ - diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs index f8b959d..768129d 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/VisitLogic.cs @@ -21,16 +21,18 @@ namespace VetClinicBusinessLogic.BusinessLogics _logger = logger; _visitStorage = visitStorage; } + public List? ReadList(VisitSearchModel? model) { - _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); - var list = model == null ? _visitStorage.GetFullList() : _visitStorage.GetFilteredList(model); + _logger.LogInformation("ReadList. NameVisit:{NameVisit}. Id:{ Id}", model?.NameVisit, model?.Id); + var list = model == null ? _visitStorage.GetFullList() : +_visitStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } - + return list; } public VisitViewModel? ReadElement(VisitSearchModel model) @@ -39,8 +41,7 @@ namespace VetClinicBusinessLogic.BusinessLogics { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadList. NameVisit:{NameVisit}. DateVisit {DateVisit}. Id:{Id}", model.NameVisit, model.DateVisit, model?.Id); - + _logger.LogInformation("ReadElement. NameVisit:{NameVisit}.Id:{ Id}", model.NameVisit, model.Id); var element = _visitStorage.GetElement(model); if (element == null) { @@ -54,7 +55,6 @@ namespace VetClinicBusinessLogic.BusinessLogics public bool Create(VisitBindingModel model) { CheckModel(model); - if (_visitStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -73,7 +73,6 @@ namespace VetClinicBusinessLogic.BusinessLogics } return true; } - public bool Delete(VisitBindingModel model) { CheckModel(model, false); @@ -85,7 +84,9 @@ namespace VetClinicBusinessLogic.BusinessLogics } return true; } - private void CheckModel(VisitBindingModel model, bool withParams = true) + + private void CheckModel(VisitBindingModel model, bool withParams = +true) { if (model == null) { @@ -95,24 +96,21 @@ namespace VetClinicBusinessLogic.BusinessLogics { return; } - if (model.NameVisit == "") + if (string.IsNullOrEmpty(model.NameVisit)) { - throw new ArgumentNullException("Имя не должно быть пустым", nameof(model.NameVisit)); + throw new ArgumentNullException("Нет названия визита", + nameof(model.NameVisit)); } - if (model.AdminId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.AdminId)); - } - if (model.DateVisit == new DateTime()) - { - throw new ArgumentNullException("Укажите Время", nameof(model.DateVisit)); - } - + + _logger.LogInformation("Medicine. Medicine:{NameVisit}. Id: { Id}", model.NameVisit, model.Id); var element = _visitStorage.GetElement(new VisitSearchModel { - Id = model.Id + NameVisit = model.NameVisit }); - + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Визит с таким названием уже есть"); + } } } } diff --git a/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj b/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj index be77928..a53042c 100644 --- a/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj +++ b/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj @@ -7,8 +7,15 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs index 1f843dd..7b162f5 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/MedicineStorage.cs @@ -28,7 +28,7 @@ namespace VetClinicDataBaseImplement.Implements using var context = new VetClinicDatabase(); return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals) .ThenInclude(x => x.Animal) - .Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName) + .Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName) && (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId))) .ToList() .Select(x => x.GetViewModel) diff --git a/VetClinic/VetClinicRestApi/Controllers/VisitController.cs b/VetClinic/VetClinicRestApi/Controllers/VisitController.cs new file mode 100644 index 0000000..136cd53 --- /dev/null +++ b/VetClinic/VetClinicRestApi/Controllers/VisitController.cs @@ -0,0 +1,94 @@ +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 VisitController : Controller + { + private readonly ILogger _logger; + private readonly IVisitLogic _visit; + public VisitController(ILogger logger, IVisitLogic visit) + { + _logger = logger; + _visit = visit; + } + + [HttpGet] + public Tuple>? GetVisit(int VisitId) + { + try + { + var elem = _visit.ReadElement(new VisitSearchModel { Id = VisitId }); + if (elem == null) + return null; + return Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.AnimalName).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения визита по id={Id}", VisitId); + throw; + } + } + [HttpGet] + public List GetVisits(int adminId) + { + try + { + return _visit.ReadList(new VisitSearchModel { AdminId = adminId}); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка визитовв"); + throw; + } + } + [HttpPost] + public bool CreateVisit(VisitBindingModel model) + { + try + { + return _visit.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать визит"); + throw; + } + } + + [HttpPost] + public bool UpdateVisit(VisitBindingModel model) + { + try + { + model.VisitAnimals = null!; + return _visit.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить визит"); + throw; + } + } + + [HttpPost] + public bool DeleteVisit(VisitBindingModel model) + { + try + { + return _visit.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления визита"); + throw; + } + } + } +} diff --git a/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj b/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj index 52c3669..51ac888 100644 --- a/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj +++ b/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj @@ -7,10 +7,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive -