Merge branch 'Worker'
This commit is contained in:
commit
6241b8f6fb
@ -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<HomeController> _logger;
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
public HomeController(ILogger<HomeController> 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<List<VisitViewModel>>($"api/visit/getvisits?vistId={APIAdmin.Admin.Id}"));
|
||||
|
||||
return View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/main/getorders?clientId={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<AdminViewModel>($"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<List<VisitViewModel>>("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<List<MedicineViewModel>>("api/shop/getvisits");
|
||||
return View();
|
||||
}
|
||||
|
||||
APIAdmin.Admin = APIAdmin.GetRequest<AdminViewModel>($"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<List<AnimalViewModel>>("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");
|
||||
}
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<VisitViewModel, string>? GetMedicine(int visitId)
|
||||
{
|
||||
if (APIAdmin.Admin == null)
|
||||
{
|
||||
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
|
||||
}
|
||||
var result = APIAdmin.GetRequest<Tuple<VisitViewModel, List<string>>>($"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 += "<tr>";
|
||||
table += $"<td>{animal}</td>";
|
||||
table += "</tr>";
|
||||
}
|
||||
return Tuple.Create(result.Item1, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VetClinicContracts\VetClinicContracts.csproj" />
|
||||
<ProjectReference Include="..\VetClinicDataBaseImplement\VetClinicDataBaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -21,16 +21,18 @@ namespace VetClinicBusinessLogic.BusinessLogics
|
||||
_logger = logger;
|
||||
_visitStorage = visitStorage;
|
||||
}
|
||||
|
||||
public List<VisitViewModel>? 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("Визит с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NETCore.App" Version="2.1.30" />
|
||||
<PackageReference Include="NPOI" Version="2.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -11,10 +11,7 @@ namespace VetClinicContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int AdminId { get; set; }
|
||||
public int VaccinationId { get; set; }
|
||||
public Dictionary<int, IVisitModel> VisitAnimals { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IMedicineModel> MedicineAnimals { get; set; } = new();
|
||||
public string AnimalName { get; set; } = string.Empty;
|
||||
|
||||
public string? Family { get; set; } = string.Empty;
|
||||
|
@ -11,10 +11,6 @@ namespace VetClinicContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? AdminId { get; set; }
|
||||
|
||||
public Dictionary<int, IVisitModel> Visits { get; set; } = new();
|
||||
public Dictionary<int, IMedicineModel> Medicines { get; set; } = new();
|
||||
|
||||
public string? AnimalName { get; set; }
|
||||
|
||||
public string? Family { get; set; }
|
||||
|
@ -12,9 +12,7 @@ namespace VetClinicContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int AdminId { get; set; }
|
||||
public int VaccinationId { get; set; }
|
||||
public Dictionary<int, IVisitModel> VisitAnimals { get; set; } = new();
|
||||
public Dictionary<int, IMedicineModel> MedicineAnimals { get; set; } = new();
|
||||
|
||||
[DisplayName("Имя животного")]
|
||||
public string AnimalName { get; set; } = string.Empty;
|
||||
|
||||
|
@ -19,7 +19,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
@ -38,7 +38,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
@ -46,7 +46,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
@ -63,7 +63,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
|
||||
return context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.Where(x => x.AdminFIO.Contains(model.AdminFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -75,7 +75,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
|
||||
return context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -93,7 +93,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => x.Id == newAdmin.Id)
|
||||
?.GetViewModel;
|
||||
@ -103,7 +103,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
{
|
||||
using var context = new VetClinicDatabase();
|
||||
var order = context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
@ -114,7 +114,7 @@ namespace VetClinicDataBaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Admins
|
||||
//.Include(x => x.Visits)
|
||||
.Include(x => x.Visits)
|
||||
.Include(x => x.Animals)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
|
@ -15,10 +15,7 @@ namespace VetClinicBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
|
||||
return context.Animals
|
||||
.Include(x => x.Vaccinations)
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -32,9 +29,6 @@ namespace VetClinicBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Animals
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Vaccinations)
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Where(x => x.AnimalName.Contains(model.AnimalName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
@ -48,9 +42,6 @@ namespace VetClinicBaseImplement.Implements
|
||||
using var context = new VetClinicDatabase();
|
||||
return context.Animals
|
||||
.Include(x => x.Admin)
|
||||
.Include(x => x.Vaccinations)
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Include(x => x.Vaccinations)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.AnimalName) && x.AnimalName == model.AnimalName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
@ -80,7 +71,6 @@ namespace VetClinicBaseImplement.Implements
|
||||
}
|
||||
animal.Update(model);
|
||||
context.SaveChanges();
|
||||
animal.UpdateVisits(context, model);
|
||||
transaction.Commit();
|
||||
return animal.GetViewModel;
|
||||
}
|
||||
@ -94,14 +84,11 @@ namespace VetClinicBaseImplement.Implements
|
||||
{
|
||||
using var context = new VetClinicDatabase();
|
||||
var element = context.Animals
|
||||
.Include(x => x.Visits)
|
||||
.ThenInclude(x => x.Visit)
|
||||
.Include(x => x.Vaccinations)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
|
||||
context.Animals.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
|
@ -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)
|
||||
|
@ -18,13 +18,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int AdminId { get; set; }
|
||||
[Required]
|
||||
public int VaccinationId { get; set; }
|
||||
|
||||
[Required]
|
||||
public Dictionary<int, IVisitModel>? _visitAnimals = null;
|
||||
[Required]
|
||||
public Dictionary<int, IMedicineModel>? _medicineAnimals = null;
|
||||
[Required]
|
||||
public string AnimalName { get; set; } = string.Empty;
|
||||
|
||||
@ -43,32 +37,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
|
||||
[ForeignKey("AnimalId")]
|
||||
public virtual List<MedicineAnimal> Medicines { get; set; } = new();
|
||||
[NotMapped]
|
||||
public Dictionary<int, IVisitModel> VisitAnimals
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_visitAnimals == null)
|
||||
{
|
||||
_visitAnimals = Visits.ToDictionary(recPC => recPC.VisitId, recPC =>
|
||||
recPC.Visit as IVisitModel);
|
||||
}
|
||||
return _visitAnimals;
|
||||
}
|
||||
}
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMedicineModel> MedicineAnimals
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_medicineAnimals == null)
|
||||
{
|
||||
_medicineAnimals = Medicines.ToDictionary(recPC => recPC.MedicineId, recPC =>
|
||||
recPC.Medicine as IMedicineModel);
|
||||
}
|
||||
return _medicineAnimals;
|
||||
}
|
||||
}
|
||||
|
||||
public static Animal? Create(VetClinicDatabase context, AnimalBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -79,18 +48,9 @@ namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
AdminId = model.AdminId,
|
||||
VaccinationId = model.VaccinationId,
|
||||
AnimalName = model.AnimalName,
|
||||
Family = model.Family,
|
||||
Visits = model.VisitAnimals.Select(x => new VisitAnimal
|
||||
{
|
||||
Visit = context.Visits.First(y => y.Id == x.Key)
|
||||
}).ToList(),
|
||||
Medicines = model.MedicineAnimals.Select(x => new MedicineAnimal
|
||||
{
|
||||
Medicine = context.Medicines.First(y => y.Id == x.Key)
|
||||
}).ToList(),
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
public void Update(AnimalBindingModel? model)
|
||||
@ -105,57 +65,11 @@ namespace VetClinicDataBaseImplement.Models
|
||||
public AnimalViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
VisitAnimals = VisitAnimals,
|
||||
AdminId = AdminId,
|
||||
VaccinationId = VaccinationId,
|
||||
AnimalName = AnimalName,
|
||||
MedicineAnimals = MedicineAnimals,
|
||||
Family = Family
|
||||
|
||||
};
|
||||
public void UpdateVisits(VetClinicDatabase context, AnimalBindingModel model)
|
||||
{
|
||||
var visitAnimals = context.VisitAnimals.Where(rec => rec.AnimalId == model.Id).ToList();
|
||||
if (visitAnimals != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.VisitId)));
|
||||
context.SaveChanges();
|
||||
|
||||
}
|
||||
var animal = context.Animals.First(x => x.Id == Id);
|
||||
foreach (var pc in model.VisitAnimals)
|
||||
{
|
||||
context.VisitAnimals.Add(new VisitAnimal
|
||||
{
|
||||
Animal = animal,
|
||||
Visit = context.Visits.First(x => x.Id == pc.Key),
|
||||
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_visitAnimals = null;
|
||||
}
|
||||
public void UpdateMedicines(VetClinicDatabase context, AnimalBindingModel model)
|
||||
{
|
||||
var medicineAnimals = context.MedicineAnimals.Where(rec => rec.AnimalId == model.Id).ToList();
|
||||
if (medicineAnimals != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.MedicineAnimals.RemoveRange(medicineAnimals.Where(rec => !model.MedicineAnimals.ContainsKey(rec.MedicineId)));
|
||||
context.SaveChanges();
|
||||
|
||||
}
|
||||
var animal = context.Animals.First(x => x.Id == Id);
|
||||
foreach (var pc in model.VisitAnimals)
|
||||
{
|
||||
context.MedicineAnimals.Add(new MedicineAnimal
|
||||
{
|
||||
Animal = animal,
|
||||
Medicine = context.Medicines.First(x => x.Id == pc.Key),
|
||||
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_medicineAnimals = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
NameVaccination = model.NameVaccination,
|
||||
CostVaccination = model.CostVaccination,
|
||||
DateStamp = model.DateStamp,
|
||||
Animal = context.Animals.FirstOrDefault(x => x.Id == model.AnimalId),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
DateStamp = model.DateStamp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public VaccinationViewModel GetViewModel => new()
|
||||
{
|
||||
AnimalId = AnimalId,
|
||||
|
@ -18,10 +18,7 @@ namespace VetClinicDataBaseImplement.Models
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int AdminId { get; set; }
|
||||
[Required]
|
||||
public Dictionary<int, IAnimalModel>? _visitAnimals = null;
|
||||
[Required]
|
||||
public Dictionary<int, IServiceModel>? _serviceVisits = null;
|
||||
|
||||
[Required]
|
||||
public string NameVisit { get; set; } = string.Empty;
|
||||
|
||||
@ -33,8 +30,11 @@ namespace VetClinicDataBaseImplement.Models
|
||||
|
||||
[ForeignKey("VisitId")]
|
||||
public virtual List<VisitService> Services { get; set; } = new();
|
||||
|
||||
public virtual Admin Admin { get; set; }
|
||||
public Dictionary<int, IAnimalModel>? _visitAnimals = null;
|
||||
|
||||
public Dictionary<int, IServiceModel>? _serviceVisits = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals
|
||||
{
|
||||
|
@ -9,9 +9,6 @@ namespace VetClinicDataModels.Models
|
||||
public interface IAnimalModel : IId
|
||||
{
|
||||
int AdminId { get; }
|
||||
Dictionary<int, IVisitModel> VisitAnimals { get; }
|
||||
|
||||
Dictionary<int, IMedicineModel> MedicineAnimals { get; }
|
||||
string AnimalName { get; }
|
||||
string? Family { get; }
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
94
VetClinic/VetClinicRestApi/Controllers/VisitController.cs
Normal file
94
VetClinic/VetClinicRestApi/Controllers/VisitController.cs
Normal file
@ -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<VisitController> logger, IVisitLogic visit)
|
||||
{
|
||||
_logger = logger;
|
||||
_visit = visit;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<VisitViewModel, List<string>>? 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<VisitViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,10 +7,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user