Добавление клиента(нужно пофиксить ошибки)
This commit is contained in:
parent
167747ecae
commit
1edcb20fce
121
Hospital/HospitalBusinessLogic/BusinessLogics/ClientLogic.cs
Normal file
121
Hospital/HospitalBusinessLogic/BusinessLogics/ClientLogic.cs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.BusinessLogicsContracts;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ClientLogic : IClientLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IClientStorage _clientStorage;
|
||||||
|
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_clientStorage = clientStorage;
|
||||||
|
}
|
||||||
|
public bool Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_clientStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||||
|
if (_clientStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}.", model.ClientFIO, model.Email, model.Id);
|
||||||
|
var element = _clientStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ClientFIO: {ClientName}. Email: {Email}. Id: {Id}.", model?.ClientFIO, model?.Email, model?.Id);
|
||||||
|
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_clientStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ClientFIO))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Client. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}", model.ClientFIO, model.Email, model.Id);
|
||||||
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
|
{
|
||||||
|
Email = model.Email
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Клиент с такой почтой уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
HospitalContracts/BindingModels/ClientBindingModel.cs
Normal file
17
HospitalContracts/BindingModels/ClientBindingModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using HospitalDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ClientBindingModel : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -12,12 +12,12 @@ namespace HospitalContracts.BindingModels
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string IllnessName { get; set; } = string.Empty;
|
public string IllnessName { get; set; } = string.Empty;
|
||||||
public string Form { get; set; } = string.Empty;
|
public string Form { get; set; } = string.Empty;
|
||||||
public Dictionary<int, (ISymptomsModel, int)> IllnessSymptoms
|
public Dictionary<int, ISymptomsModel> IllnessSymptoms
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
public Dictionary<int, (IKurseModel, int)> IllnessKurse
|
public Dictionary<int, IKurseModel> IllnessKurse
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -14,13 +14,13 @@ namespace HospitalContracts.BindingModels
|
|||||||
public DateTime Date { get; set; } = DateTime.Now;
|
public DateTime Date { get; set; } = DateTime.Now;
|
||||||
public string ModeOfApplication { get; set; } = string.Empty;
|
public string ModeOfApplication { get; set; } = string.Empty;
|
||||||
public int MedicinesId { get; set; }
|
public int MedicinesId { get; set; }
|
||||||
public Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms
|
public Dictionary<int, ISymptomsModel> RecipeSymptoms
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
|
|
||||||
public Dictionary<int, (IProceduresModel, int)> RecipeProcedures
|
public Dictionary<int, IProceduresModel> RecipeProcedures
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
20
HospitalContracts/BusinessLogicsContracts/IClientLogic.cs
Normal file
20
HospitalContracts/BusinessLogicsContracts/IClientLogic.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IClientLogic
|
||||||
|
{
|
||||||
|
List<ClientViewModel>? ReadList(ClientSearchModel? model);
|
||||||
|
ClientViewModel? ReadElement(ClientSearchModel model);
|
||||||
|
bool Create(ClientBindingModel model);
|
||||||
|
bool Update(ClientBindingModel model);
|
||||||
|
bool Delete(ClientBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
16
HospitalContracts/SearchModels/ClientSearchModel.cs
Normal file
16
HospitalContracts/SearchModels/ClientSearchModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ClientSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ClientFIO { get; set; }
|
||||||
|
public string? Email { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ namespace HospitalContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public class SymptomsSearchModel
|
public class SymptomsSearchModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? SymptomName { get; set; }
|
public string? SymptomName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
HospitalContracts/StoragesContracts/IClientStorage.cs
Normal file
21
HospitalContracts/StoragesContracts/IClientStorage.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IClientStorage
|
||||||
|
{
|
||||||
|
List<ClientViewModel> GetFullList();
|
||||||
|
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
|
||||||
|
ClientViewModel? GetElement(ClientSearchModel model);
|
||||||
|
ClientViewModel? Insert(ClientBindingModel model);
|
||||||
|
ClientViewModel? Update(ClientBindingModel model);
|
||||||
|
ClientViewModel? Delete(ClientBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
21
HospitalContracts/ViewModels/ClientViewModel.cs
Normal file
21
HospitalContracts/ViewModels/ClientViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using HospitalDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ClientViewModel : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("ФИО клиента")]
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Логин (эл. почта)")]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Пароль")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -12,15 +12,15 @@ namespace HospitalContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Название болезни")]
|
[DisplayName("Название болезни")]
|
||||||
public string IllnessName { get; set; }
|
public string IllnessName { get; set; } = string.Empty;
|
||||||
[DisplayName("Форма болезни")]
|
[DisplayName("Форма болезни")]
|
||||||
public string Form { get; set; }
|
public string Form { get; set; } = string.Empty;
|
||||||
public Dictionary<int, (ISymptomsModel, int)> IllnessSymptoms
|
public Dictionary<int, ISymptomsModel> IllnessSymptoms
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
public Dictionary<int, (IKurseModel, int)> IllnessKurse
|
public Dictionary<int, IKurseModel> IllnessKurse
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -12,11 +12,11 @@ namespace HospitalContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Продолжительность курса")]
|
[DisplayName("Продолжительность курса")]
|
||||||
public string Duration { get; set; }
|
public string Duration { get; set; } = string.Empty;
|
||||||
[DisplayName("Срок приема")]
|
[DisplayName("Срок приема")]
|
||||||
public int CountInDay { get; set; }
|
public int CountInDay { get; set; }
|
||||||
public int MedicinesId { get; set; }
|
public int MedicinesId { get; set; }
|
||||||
[DisplayName("Название лекарства")]
|
[DisplayName("Название лекарства")]
|
||||||
public string MedicinesName { get; set; }
|
public string MedicinesName { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ namespace HospitalContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Название лекарства")]
|
[DisplayName("Название лекарства")]
|
||||||
public string MedicinesName { get; set; }
|
public string MedicinesName { get; set; } = string.Empty;
|
||||||
[DisplayName("Группа")]
|
[DisplayName("Группа")]
|
||||||
public string Group { get; set; }
|
public string Group { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ namespace HospitalContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Название процедуры")]
|
[DisplayName("Название процедуры")]
|
||||||
public string ProceduresName { get; set; }
|
public string ProceduresName { get; set; } = string.Empty;
|
||||||
[DisplayName("Тип процедуры")]
|
[DisplayName("Тип процедуры")]
|
||||||
public string Type { get; set; }
|
public string Type { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,21 +12,21 @@ namespace HospitalContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Доза")]
|
[DisplayName("Доза")]
|
||||||
public string Dose { get; set; }
|
public string Dose { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата выписки")]
|
[DisplayName("Дата выписки")]
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
[DisplayName("Способ приготовления")]
|
[DisplayName("Способ приготовления")]
|
||||||
public string ModeOfApplication { get; set; }
|
public string ModeOfApplication { get; set; } = string.Empty;
|
||||||
[DisplayName("Лекарство")]
|
[DisplayName("Лекарство")]
|
||||||
public int MedicinesId { get; set; }
|
public int MedicinesId { get; set; }
|
||||||
[DisplayName("Симптом")]
|
[DisplayName("Симптом")]
|
||||||
public Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms
|
public Dictionary<int, ISymptomsModel> RecipeSymptoms
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new();
|
} = new();
|
||||||
[DisplayName("Процедура")]
|
[DisplayName("Процедура")]
|
||||||
public Dictionary<int, (IProceduresModel, int)> RecipeProcedures
|
public Dictionary<int, IProceduresModel> RecipeProcedures
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -12,8 +12,8 @@ namespace HospitalContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Симптом")]
|
[DisplayName("Симптом")]
|
||||||
public string SymptomName { get; set; }
|
public string SymptomName { get; set; } = string.Empty;
|
||||||
[DisplayName("Описание")]
|
[DisplayName("Описание")]
|
||||||
public string Description { get; set; }
|
public string Description { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,8 @@ namespace HospitalDataBaseImplements
|
|||||||
public virtual DbSet<Symptoms> Symptomses { set; get; }
|
public virtual DbSet<Symptoms> Symptomses { set; get; }
|
||||||
public virtual DbSet<Recipes> Recipes { set; get; }
|
public virtual DbSet<Recipes> Recipes { set; get; }
|
||||||
public virtual DbSet<Medicines> Medicines { set; get; }
|
public virtual DbSet<Medicines> Medicines { set; get; }
|
||||||
|
public virtual DbSet<Procedures> Procedures { set; get; }
|
||||||
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
83
HospitalDataBaseImplements/Implements/ClientStorage.cs
Normal file
83
HospitalDataBaseImplements/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataBaseImplements.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalDataBaseImplements.Implements
|
||||||
|
{
|
||||||
|
public class ClientStorage : IClientStorage
|
||||||
|
{
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Clients.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||||
|
return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))?.GetViewModel;
|
||||||
|
if (!string.IsNullOrEmpty(model.Email))
|
||||||
|
return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ClientFIO))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Clients.Where(x => x.ClientFIO.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Clients.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var newClient = Client.Create(model);
|
||||||
|
if (newClient == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
context.Clients.Add(newClient);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newClient.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
client.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,9 @@
|
|||||||
using System;
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataBaseImplements.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -6,7 +11,71 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace HospitalDataBaseImplements.Implements
|
namespace HospitalDataBaseImplements.Implements
|
||||||
{
|
{
|
||||||
public class KurseStorage
|
public class KurseStorage : IKurseStorage
|
||||||
{
|
{
|
||||||
|
public KurseViewModel? Delete(KurseBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var element = context.Kurse.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Kurse.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KurseViewModel? GetElement(KurseSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Kurse.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<KurseViewModel> GetFilteredList(KurseSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Kurse.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<KurseViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Kurse.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KurseViewModel? Insert(KurseBindingModel model)
|
||||||
|
{
|
||||||
|
var newKurse = Kurses.Create(model);
|
||||||
|
if (newKurse == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
context.Kurse.Add(newKurse);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newKurse.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KurseViewModel? Update(KurseBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var kurse = context.Kurse.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (kurse == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
kurse.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return kurse.GetViewModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
using System;
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataBaseImplements.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -6,7 +11,76 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace HospitalDataBaseImplements.Implements
|
namespace HospitalDataBaseImplements.Implements
|
||||||
{
|
{
|
||||||
public class MedicinesStorage
|
public class MedicinesStorage : IMedicinesStorage
|
||||||
{
|
{
|
||||||
|
public List<MedicinesViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Medicines
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<MedicinesViewModel> GetFilteredList(MedicinesSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.MedicinesName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Medicines
|
||||||
|
.Where(x => x.MedicinesName.Contains(model.MedicinesName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public MedicinesViewModel? GetElement(MedicinesSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.MedicinesName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Medicines
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.MedicinesName) && x.MedicinesName ==
|
||||||
|
model.MedicinesName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public MedicinesViewModel? Insert(MedicinesBindingModel model)
|
||||||
|
{
|
||||||
|
var newMedicine = Medicines.Create(model);
|
||||||
|
if (newMedicine == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
context.Medicines.Add(newMedicine);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newMedicine.GetViewModel;
|
||||||
|
}
|
||||||
|
public MedicinesViewModel? Update(MedicinesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var medicine = context.Medicines.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (medicine == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
medicine.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return medicine.GetViewModel;
|
||||||
|
}
|
||||||
|
public MedicinesViewModel? Delete(MedicinesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var element = context.Medicines.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Medicines.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
using System;
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataBaseImplements.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -6,7 +11,76 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace HospitalDataBaseImplements.Implements
|
namespace HospitalDataBaseImplements.Implements
|
||||||
{
|
{
|
||||||
public class ProceduresStorage
|
public class ProceduresStorage : IProceduresStorage
|
||||||
{
|
{
|
||||||
|
public List<ProceduresViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Procedures
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<ProceduresViewModel> GetFilteredList(ProceduresSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ProceduresName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Procedures
|
||||||
|
.Where(x => x.ProceduresName.Contains(model.ProceduresName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public ProceduresViewModel? GetElement(ProceduresSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ProceduresName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Procedures
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ProceduresName) && x.ProceduresName ==
|
||||||
|
model.ProceduresName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ProceduresViewModel? Insert(ProceduresBindingModel model)
|
||||||
|
{
|
||||||
|
var newProcedures = Procedures.Create(model);
|
||||||
|
if (newProcedures == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
context.Procedures.Add(newProcedures);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newProcedures.GetViewModel;
|
||||||
|
}
|
||||||
|
public ProceduresViewModel? Update(ProceduresBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var procedure = context.Procedures.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (procedure == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
procedure.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return procedure.GetViewModel;
|
||||||
|
}
|
||||||
|
public ProceduresViewModel? Delete(ProceduresBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var element = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Procedures.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
using System;
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataBaseImplements.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -6,7 +11,71 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace HospitalDataBaseImplements.Implements
|
namespace HospitalDataBaseImplements.Implements
|
||||||
{
|
{
|
||||||
public class RecipesStorage
|
public class RecipesStorage : IRecipesStorage
|
||||||
{
|
{
|
||||||
|
public RecipesViewModel? Delete(RecipesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var element = context.Recipes.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Recipes.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecipesViewModel? GetElement(RecipesSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Recipes.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RecipesViewModel> GetFilteredList(RecipesSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Recipes.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RecipesViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Recipes.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecipesViewModel? Insert(RecipesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var newRecipe = Recipes.Create(context, model);
|
||||||
|
if (newRecipe == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Recipes.Add(newRecipe);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newRecipe.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecipesViewModel? Update(RecipesBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var recipe = context.Recipes.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (recipe == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
recipe.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return recipe.GetViewModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
using System;
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.SearchModels;
|
||||||
|
using HospitalContracts.StoragesContracts;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataBaseImplements.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -6,7 +11,76 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace HospitalDataBaseImplements.Implements
|
namespace HospitalDataBaseImplements.Implements
|
||||||
{
|
{
|
||||||
public class SymptomsStorage
|
public class SymptomsStorage : ISymptomsStorage
|
||||||
{
|
{
|
||||||
|
public List<SymptomsViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Symptomses
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<SymptomsViewModel> GetFilteredList(SymptomsSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SymptomName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Symptomses
|
||||||
|
.Where(x => x.SymptomName.Contains(model.SymptomName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public SymptomsViewModel? GetElement(SymptomsSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SymptomName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
return context.Symptomses
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.SymptomName) && x.SymptomName ==
|
||||||
|
model.SymptomName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public SymptomsViewModel? Insert(SymptomsBindingModel model)
|
||||||
|
{
|
||||||
|
var newSymptoms = Symptoms.Create(model);
|
||||||
|
if (newSymptoms == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
context.Symptomses.Add(newSymptoms);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newSymptoms.GetViewModel;
|
||||||
|
}
|
||||||
|
public SymptomsViewModel? Update(SymptomsBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var symptom = context.Symptomses.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (symptom == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
symptom.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return symptom.GetViewModel;
|
||||||
|
}
|
||||||
|
public SymptomsViewModel? Delete(SymptomsBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new HospitalDatabase();
|
||||||
|
var element = context.Symptomses.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Symptomses.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
71
HospitalDataBaseImplements/Models/Client.cs
Normal file
71
HospitalDataBaseImplements/Models/Client.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using HospitalContracts.BindingModels;
|
||||||
|
using HospitalContracts.ViewModels;
|
||||||
|
using HospitalDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalDataBaseImplements.Models
|
||||||
|
{
|
||||||
|
public class Client : IClientModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[ForeignKey("ClientId")]
|
||||||
|
//public virtual List<Medicines> Medicines { get; set; } = new();
|
||||||
|
//public virtual List<Procedures> Procedures { get; set; } = new();
|
||||||
|
//public virtual List<Recipes> Recipes { get; set; } = new();
|
||||||
|
|
||||||
|
public static Client? Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Client Create(ClientViewModel model)
|
||||||
|
{
|
||||||
|
return new Client
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClientFIO = model.ClientFIO;
|
||||||
|
Email = model.Email;
|
||||||
|
Password = model.Password;
|
||||||
|
}
|
||||||
|
public ClientViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ClientFIO = ClientFIO,
|
||||||
|
Email = Email,
|
||||||
|
Password = Password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -18,16 +18,15 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
public string IllnessName { get; private set; } = string.Empty;
|
public string IllnessName { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Form { get; private set; } = string.Empty;
|
public string Form { get; private set; } = string.Empty;
|
||||||
private Dictionary<int, (IKurseModel, int)>? _illnessKurses = null;
|
private Dictionary<int, IKurseModel>? _illnessKurses = null;
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IKurseModel, int)> IllnessKurse
|
public Dictionary<int, IKurseModel> IllnessKurse
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_illnessKurses == null)
|
if (_illnessKurses == null)
|
||||||
{
|
{
|
||||||
_illnessKurses = Kurses.ToDictionary(recPC => recPC.KurseId, recPC =>
|
_illnessKurses = Kurses.ToDictionary(recPC => recPC.KurseId, recPC => (recPC.Kurse as IKurseModel));
|
||||||
(recPC.Kurse as IKurseModel, recPC.Count));
|
|
||||||
}
|
}
|
||||||
return _illnessKurses;
|
return _illnessKurses;
|
||||||
}
|
}
|
||||||
@ -35,15 +34,15 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
[ForeignKey("IllnessId")]
|
[ForeignKey("IllnessId")]
|
||||||
public virtual List<IllnessKurse> Kurses { get; set; } = new();
|
public virtual List<IllnessKurse> Kurses { get; set; } = new();
|
||||||
|
|
||||||
private Dictionary<int, (ISymptomsModel, int)>? _illnessSymptomses = null;
|
private Dictionary<int, ISymptomsModel>? _illnessSymptomses = null;
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (ISymptomsModel, int)> IllnessSymptoms
|
public Dictionary<int, ISymptomsModel> IllnessSymptoms
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_illnessSymptomses == null)
|
if (_illnessSymptomses == null)
|
||||||
{
|
{
|
||||||
_illnessSymptomses = Symptomses.ToDictionary(recPC => recPC.SymptomsId, recPC =>(recPC.Symptoms as ISymptomsModel, recPC.Count));
|
_illnessSymptomses = Symptomses.ToDictionary(recPC => recPC.SymptomsId, recPC => (recPC.Symptoms as ISymptomsModel));
|
||||||
}
|
}
|
||||||
return _illnessSymptomses;
|
return _illnessSymptomses;
|
||||||
}
|
}
|
||||||
@ -61,12 +60,10 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
Kurses = model.IllnessKurse.Select(x => new IllnessKurse
|
Kurses = model.IllnessKurse.Select(x => new IllnessKurse
|
||||||
{
|
{
|
||||||
Kurse = context.Kurse.First(y => y.Id == x.Key),
|
Kurse = context.Kurse.First(y => y.Id == x.Key),
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
Symptomses = model.IllnessSymptoms.Select(x => new IllnessSymptoms
|
Symptomses = model.IllnessSymptoms.Select(x => new IllnessSymptoms
|
||||||
{
|
{
|
||||||
Symptoms = context.Symptomses.First(y => y.Id == x.Key),
|
Symptoms = context.Symptomses.First(y => y.Id == x.Key),
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList()
|
}).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -91,14 +88,6 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
context.IllnessKurse.RemoveRange(illnessKurses.Where(rec
|
context.IllnessKurse.RemoveRange(illnessKurses.Where(rec
|
||||||
=> !model.IllnessKurse.ContainsKey(rec.KurseId)));
|
=> !model.IllnessKurse.ContainsKey(rec.KurseId)));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
// обновили количество у существующих записей
|
|
||||||
foreach (var updateDrugCourse in illnessKurses)
|
|
||||||
{
|
|
||||||
updateDrugCourse.Count =
|
|
||||||
model.IllnessKurse[updateDrugCourse.KurseId].Item2;
|
|
||||||
model.IllnessKurse.Remove(updateDrugCourse.KurseId);
|
|
||||||
}
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
}
|
||||||
var illness = context.Illnesses.First(x => x.Id == Id);
|
var illness = context.Illnesses.First(x => x.Id == Id);
|
||||||
foreach (var pc in model.IllnessKurse)
|
foreach (var pc in model.IllnessKurse)
|
||||||
@ -106,8 +95,7 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
context.IllnessKurse.Add(new IllnessKurse
|
context.IllnessKurse.Add(new IllnessKurse
|
||||||
{
|
{
|
||||||
Illness = illness,
|
Illness = illness,
|
||||||
Kurse = context.Kurse.First(x => x.Id == pc.Key),
|
Kurse = context.Kurse.First(x => x.Id == pc.Key)
|
||||||
Count = pc.Value.Item2
|
|
||||||
});
|
});
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
@ -121,14 +109,6 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
context.IllnessSymptomses.RemoveRange(illnessSymptomses.Where(rec
|
context.IllnessSymptomses.RemoveRange(illnessSymptomses.Where(rec
|
||||||
=> !model.IllnessSymptoms.ContainsKey(rec.SymptomsId)));
|
=> !model.IllnessSymptoms.ContainsKey(rec.SymptomsId)));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
// обновили количество у существующих записей
|
|
||||||
foreach (var updateSymptoms in illnessSymptomses)
|
|
||||||
{
|
|
||||||
updateSymptoms.Count =
|
|
||||||
model.IllnessSymptoms[updateSymptoms.SymptomsId].Item2;
|
|
||||||
model.IllnessSymptoms.Remove(updateSymptoms.SymptomsId);
|
|
||||||
}
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
}
|
||||||
var illness = context.Illnesses.First(x => x.Id == Id);
|
var illness = context.Illnesses.First(x => x.Id == Id);
|
||||||
foreach (var pc in model.IllnessSymptoms)
|
foreach (var pc in model.IllnessSymptoms)
|
||||||
@ -136,8 +116,7 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
context.IllnessSymptomses.Add(new IllnessSymptoms
|
context.IllnessSymptomses.Add(new IllnessSymptoms
|
||||||
{
|
{
|
||||||
Illness = illness,
|
Illness = illness,
|
||||||
Symptoms = context.Symptomses.First(x => x.Id == pc.Key),
|
Symptoms = context.Symptomses.First(x => x.Id == pc.Key)
|
||||||
Count = pc.Value.Item2
|
|
||||||
});
|
});
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public int KurseId { get; set; }
|
public int KurseId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
|
||||||
public virtual Illness Illness { get; set; } = new();
|
public virtual Illness Illness { get; set; } = new();
|
||||||
public virtual Kurses Kurse { get; set; } = new();
|
public virtual Kurses Kurse { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public int SymptomsId { get; set; }
|
public int SymptomsId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
|
||||||
public virtual Illness Illness { get; set; } = new();
|
public virtual Illness Illness { get; set; } = new();
|
||||||
public virtual Symptoms Symptoms { get; set; } = new();
|
public virtual Symptoms Symptoms { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
@ -21,80 +21,109 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
public int MedicinesId { get; private set; }
|
public int MedicinesId { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string ModeOfApplication { get; private set; } = string.Empty;
|
public string ModeOfApplication { get; private set; } = string.Empty;
|
||||||
private Dictionary<int, (IProceduresModel, int)>? _recipeProcedures = null;
|
private Dictionary<int, IProceduresModel>? _recipeProcedures = null;
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IProceduresModel, int)> RecipeProcedures
|
public Dictionary<int, IProceduresModel> RecipeProcedures
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_recipeProcedures == null)
|
if (_recipeProcedures == null)
|
||||||
{
|
{
|
||||||
// _illnessProcedures = Procedures.ToDictionary(recPC => recPC.KurseId, recPC =>
|
_recipeProcedures = Procedures.ToDictionary(recPC => recPC.ProcedureId, recPC =>
|
||||||
//(recPC.Kurse as IProceduresModel, recPC.Count));
|
recPC.Procedures as IProceduresModel);
|
||||||
}
|
}
|
||||||
return _recipeProcedures;
|
return _recipeProcedures;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ForeignKey("ProceduresId")] /////////////////
|
[ForeignKey("ProceduresId")]
|
||||||
public virtual List<RecipesProcedures> Procedures { get; set; } = new();
|
public virtual List<RecipesProcedures> Procedures { get; set; } = new();
|
||||||
|
|
||||||
private Dictionary<int, (ISymptomsModel, int)>? _recipeSymptoms = null;
|
private Dictionary<int, ISymptomsModel>? _recipeSymptoms = null;
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms
|
public Dictionary<int, ISymptomsModel> RecipeSymptoms
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_recipeSymptoms == null)
|
if (_recipeSymptoms == null)
|
||||||
{
|
{
|
||||||
// _recipeSymptoms = Symptoms.ToDictionary(recPC => recPC.SymptomsId, recPC => (recPC.Symptoms as ISymptomsModel, recPC.Count));
|
_recipeSymptoms = Symptoms.ToDictionary(recPC => recPC.SymptomsId, recPC => (recPC.Symptoms as ISymptomsModel));
|
||||||
}
|
}
|
||||||
return _recipeSymptoms;
|
return _recipeSymptoms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ForeignKey("SymptomsId")] /////////////////
|
[ForeignKey("SymptomsId")]
|
||||||
public virtual List<RecipesSymptoms> Symptoms { get; set; } = new();
|
public virtual List<RecipesSymptoms> Symptoms { get; set; } = new();
|
||||||
//[Required]
|
|
||||||
//public int SymptomsId { get; private set; }
|
|
||||||
//public string SymptomsName { get; private set; } = string.Empty;
|
|
||||||
//public virtual Symptoms Symptoms { get; set; } = new();
|
|
||||||
public static Recipes? Create(RecipesBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static Recipes Create(HospitalDatabase context, RecipesBindingModel model)
|
||||||
|
{
|
||||||
return new Recipes()
|
return new Recipes()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Dose = model.Dose,
|
|
||||||
Date = model.Date,
|
Date = model.Date,
|
||||||
ModeOfApplication = model.ModeOfApplication,
|
MedicinesId = model.MedicinesId,
|
||||||
//SymptomsId = model.SymptomsId,
|
Procedures = model.RecipeProcedures.Select(x => new RecipesProcedures
|
||||||
//SymptomsName = model.SymptomsName
|
{
|
||||||
|
Procedures = context.Procedures.First(y => y.Id == x.Key),
|
||||||
|
}).ToList(),
|
||||||
|
Symptoms = model.RecipeSymptoms.Select(x => new RecipesSymptoms
|
||||||
|
{
|
||||||
|
Symptoms = context.Symptomses.First(y => y.Id == x.Key),
|
||||||
|
}).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public void Update(RecipesBindingModel model)
|
||||||
public void Update(RecipesBindingModel? model)
|
|
||||||
{
|
{
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Dose = model.Dose;
|
|
||||||
Date = model.Date;
|
Date = model.Date;
|
||||||
ModeOfApplication = model.ModeOfApplication;
|
MedicinesId = model.MedicinesId;
|
||||||
//SymptomsName = model.SymptomsName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipesViewModel GetViewModel => new()
|
public RecipesViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Dose = Dose,
|
|
||||||
Date = Date,
|
Date = Date,
|
||||||
ModeOfApplication = ModeOfApplication,
|
RecipeProcedures = RecipeProcedures,
|
||||||
//SymptomsId = SymptomsId,
|
RecipeSymptoms = RecipeSymptoms
|
||||||
//SymptomsName = SymptomsName
|
|
||||||
};
|
};
|
||||||
|
public void UpdateProcedures(HospitalDatabase context, RecipesBindingModel model)
|
||||||
|
{
|
||||||
|
var recipeProcedures = context.RecipesProcedures.Where(rec => rec.RecipeId == model.Id).ToList();
|
||||||
|
if (recipeProcedures != null && recipeProcedures.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.RecipesProcedures.RemoveRange(recipeProcedures.Where(rec
|
||||||
|
=> !model.RecipeProcedures.ContainsKey(rec.ProcedureId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var recipe = context.Recipes.First(x => x.Id == Id);
|
||||||
|
foreach (var pc in model.RecipeProcedures)
|
||||||
|
{
|
||||||
|
context.RecipesProcedures.Add(new RecipesProcedures
|
||||||
|
{
|
||||||
|
Recipes = recipe,
|
||||||
|
Procedures = context.Procedures.First(x => x.Id == pc.Key)
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_recipeProcedures = null;
|
||||||
|
}
|
||||||
|
public void UpdateSymptomses(HospitalDatabase context, RecipesBindingModel model)
|
||||||
|
{
|
||||||
|
var recipeSymptomses = context.RecipesSymptoms.Where(rec => rec.RecipeId == model.Id).ToList();
|
||||||
|
if (recipeSymptomses != null && recipeSymptomses.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.RecipesSymptoms.RemoveRange(recipeSymptomses.Where(rec
|
||||||
|
=> !model.RecipeSymptoms.ContainsKey(rec.SymptomsId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var recipe = context.Recipes.First(x => x.Id == Id);
|
||||||
|
foreach (var pc in model.RecipeSymptoms)
|
||||||
|
{
|
||||||
|
context.RecipesSymptoms.Add(new RecipesSymptoms
|
||||||
|
{
|
||||||
|
Recipes = recipe,
|
||||||
|
Symptoms = context.Symptomses.First(x => x.Id == pc.Key)
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_recipeSymptoms = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,5 +9,12 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
{
|
{
|
||||||
public class RecipesProcedures
|
public class RecipesProcedures
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int RecipeId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int ProcedureId { get; set; }
|
||||||
|
public virtual Recipes Recipes { get; set; } = new();
|
||||||
|
public virtual Procedures Procedures { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,5 +9,12 @@ namespace HospitalDataBaseImplements.Models
|
|||||||
{
|
{
|
||||||
public class RecipesSymptoms
|
public class RecipesSymptoms
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int RecipeId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int SymptomsId { get; set; }
|
||||||
|
public virtual Recipes Recipes { get; set; } = new();
|
||||||
|
public virtual Symptoms Symptoms { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
HospitalDataModels/Models/IClientModel.cs
Normal file
15
HospitalDataModels/Models/IClientModel.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HospitalDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IClientModel : IId
|
||||||
|
{
|
||||||
|
string ClientFIO { get; }
|
||||||
|
string Email { get; }
|
||||||
|
string Password { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ namespace HospitalDataModels.Models
|
|||||||
{
|
{
|
||||||
string IllnessName { get; }
|
string IllnessName { get; }
|
||||||
string Form { get; }
|
string Form { get; }
|
||||||
Dictionary<int, (ISymptomsModel, int)> IllnessSymptoms { get; }
|
Dictionary<int, ISymptomsModel> IllnessSymptoms { get; }
|
||||||
Dictionary<int, (IKurseModel, int)> IllnessKurse { get; }
|
Dictionary<int, IKurseModel> IllnessKurse { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace HospitalDataModels.Models
|
|||||||
DateTime Date { get; }
|
DateTime Date { get; }
|
||||||
string ModeOfApplication { get; }
|
string ModeOfApplication { get; }
|
||||||
int MedicinesId { get; }
|
int MedicinesId { get; }
|
||||||
Dictionary<int, (IProceduresModel, int)> RecipeProcedures { get; }
|
Dictionary<int, IProceduresModel> RecipeProcedures { get; }
|
||||||
Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms { get; }
|
Dictionary<int, ISymptomsModel> RecipeSymptoms { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user