Начало есть. Оформила клиента и что-то похожее на модели и логику......

This commit is contained in:
Allllen4a 2024-04-21 22:09:13 +04:00
parent d9eac56d51
commit 6cf6b09dcc
44 changed files with 1878 additions and 15 deletions

View File

@ -19,7 +19,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="BusinessLogic\" />
<Folder Include="OfficePackage\" />
</ItemGroup>

View File

@ -0,0 +1,156 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BeautySalonBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
private readonly int _passwordMaxLength = 50;
private readonly int _passwordMinLength = 10;
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. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}",
model.ClientLogin, model.ClientFIO, model.ClientEmail, 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. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}",
model?.ClientLogin, model?.ClientFIO, model?.ClientEmail, 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.ClientLogin))
{
throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientLogin));
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.ClientEmail))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.ClientEmail));
}
if (string.IsNullOrEmpty(model.ClientPassword))
{
throw new ArgumentNullException("Нет пароля", nameof(model.ClientPassword));
}
if (model.ClientPassword.Length < _passwordMinLength)
{
throw new ArgumentNullException("Пароль слишком короткий", nameof(model.ClientPassword));
}
if (model.ClientPassword.Length > _passwordMaxLength)
{
throw new ArgumentNullException("Пароль слишком длинный", nameof(model.ClientPassword));
}
_logger.LogInformation("Client. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}",
model.ClientLogin, model.ClientFIO, model.ClientEmail, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
ClientEmail = model.ClientEmail
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с такой почтой уже есть");
}
}
}
}

View File

@ -0,0 +1,107 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonBusinessLogic.BusinessLogics
{
public class EvaluationLogic : IEvaluationLogic
{
private readonly ILogger _logger;
private readonly IEvaluationStorage _evaluationStorage;
public EvaluationLogic(ILogger<EvaluationLogic> logger, IEvaluationStorage evaluationStorage)
{
_logger = logger;
_evaluationStorage = evaluationStorage;
}
public int GetNumberOfPages(int userId, int pageSize = 10)
{
return _evaluationStorage.GetNumberOfPages(userId, pageSize);
}
public List<EvaluationViewModel>? ReadList(EvaluationSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}",
model?.Id);
var list = model == null ? _evaluationStorage.GetFullList() :
_evaluationStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public EvaluationViewModel? ReadElement(EvaluationSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}", model.Id);
var element = _evaluationStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(EvaluationBindingModel model)
{
CheckModel(model);
if (_evaluationStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(EvaluationBindingModel model)
{
CheckModel(model);
if (_evaluationStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(EvaluationBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_evaluationStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EvaluationBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.PointsProcedure <= 0)
{
throw new ArgumentNullException("Оценки за процедуру должны быть больше 0", nameof(model.PointsProcedure));
}
_logger.LogInformation("Rating. PointsProcedure: {PointsProcedure}}. Id: {Id}",
model.PointsProcedure, model.PointsCosmetics, model.Id);
}
}
}

View File

@ -0,0 +1,106 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<StaffMemberLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public int GetNumberOfPages(int userId, int pageSize = 10)
{
return _orderStorage.GetNumberOfPages(userId, pageSize);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("Order. OrderID:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. OrderDate: {OrderDate}. Id: {Id}",
model.OrderDate, model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(OrderBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_orderStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.OrderAmount <= 0)
{
throw new ArgumentNullException("Cумма заказа должна быть больше 0",
nameof(model.OrderAmount));
}
}
}
}

View File

@ -0,0 +1,123 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonBusinessLogic.BusinessLogics
{
public class ProcedureLogic : IProcedureLogic
{
private readonly ILogger _logger;
private readonly IProcedureStorage _procedureStorage;
public ProcedureLogic(ILogger<ProcedureLogic> logger, IProcedureStorage procedureStorage)
{
_logger = logger;
_procedureStorage = procedureStorage;
}
public int GetNumberOfPages(int userId, int pageSize = 10)
{
return _procedureStorage.GetNumberOfPages(userId, pageSize);
}
public List<ProcedureViewModel>? ReadList(ProcedureSearchModel? model)
{
_logger.LogInformation("ReadList. ProcedureName: {ProcedureName}. Id: {Id}",
model?.ProcedureName, model?.Id);
var list = model == null ? _procedureStorage.GetFullList() :
_procedureStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ProcedureViewModel? ReadElement(ProcedureSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ProcedureName: {ProcedureName}. Id: {Id}",
model.ProcedureName, model.Id);
var element = _procedureStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(ProcedureBindingModel model)
{
CheckModel(model);
if (_procedureStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ProcedureBindingModel model)
{
CheckModel(model);
if (_procedureStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ProcedureBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_procedureStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ProcedureBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ProcedureName))
{
throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProcedureName));
}
if (model.ProcedurePrice <= 0)
{
throw new ArgumentNullException("Цена процедуры должна быть больше 0",
nameof(model.ProcedurePrice));
}
_logger.LogInformation("Procedure. ProcedureName: {ProcedureName}. Cost: {Cost}. Id: {Id}",
model.ProcedureName, model.ProcedurePrice, model.Id);
var element = _procedureStorage.GetElement(new ProcedureSearchModel
{
ProcedureName = model.ProcedureName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Процедура с таким названием уже есть");
}
}
}
}

View File

@ -10,12 +10,4 @@
<ProjectReference Include="..\BeautySalonDataModels\BeautySalonDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="BindingModels\" />
<Folder Include="SearchModels\" />
<Folder Include="BusinessLogicContracts\" />
<Folder Include="ViewModels\" />
<Folder Include="StoragesContracts\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
using BeautySalonDataModels.Models;
namespace BeautySalonContracts.BindingModels
{
public class ClientBindingModel : IClientModel
{
public int Id { get; set; }
public string ClientLogin { get; set; } = string.Empty;
public string ClientFIO { get; set; } = string.Empty;
public string ClientEmail { get; set; } = string.Empty;
public string ClientPassword { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,14 @@
using BeautySalonDataModels.Models;
namespace BeautySalonContracts.BindingModels
{
public class EvaluationBindingModel : IEvaluationModel
{
public int Id { get; set; }
public double PointsProcedure { get; set; }
public double PointsCosmetics { get; set; }
public int ProcedureId { get; set; }
public int ClientId { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
namespace BeautySalonContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public double OrderAmount { get; set; }
public int ClientId { get; set; }
public List<OrderServiceViewModel> OrderServices { get; set; } = new();
public List<OrderCosmeticViewModel> OrderCosmetics { get; set; } = new();
public List<OrderProcedureViewModel> OrderProcedures { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.Collections.Generic;
namespace BeautySalonContracts.BindingModels
{
public class ProcedureBindingModel : IProcedureModel
{
public int Id { get; set; }
public string ProcedureName { get; set; } = string.Empty;
public double ProcedurePrice { get; set; }
public double ProcedureDuration { get; set; }
public int ClientId { get; set; }
public List<ProcedureEvaluationViewModel> ProcedureCosmetics { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonContracts.SearchModels;
namespace BeautySalonContracts.BusinessLogicContracts
{
public interface IClientLogic
{
List<ClientViewModel>? ReadList(ClientSearchModel? model);
ClientViewModel? ReadElement(ClientSearchModel model);
bool Create(ClientBindingModel model);
bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonContracts.SearchModels;
namespace BeautySalonContracts.BusinessLogicContracts
{
public interface IEvaluationLogic
{
List<EvaluationViewModel>? ReadList(EvaluationSearchModel? model);
EvaluationViewModel? ReadElement(EvaluationSearchModel model);
bool Create(EvaluationBindingModel model);
bool Update(EvaluationBindingModel model);
bool Delete(EvaluationBindingModel model);
int GetNumberOfPages(int userId, int pageSize = 10);
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonContracts.SearchModels;
namespace BeautySalonContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool Create(OrderBindingModel model);
bool Delete(OrderBindingModel model);
bool Update(OrderBindingModel model);
int GetNumberOfPages(int userId, int pageSize = 10);
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonContracts.SearchModels;
namespace BeautySalonContracts.BusinessLogicContracts
{
public interface IProcedureLogic
{
List<ProcedureViewModel>? ReadList(ProcedureSearchModel? model);
ProcedureViewModel? ReadElement(ProcedureSearchModel model);
bool Create(ProcedureBindingModel model);
bool Update(ProcedureBindingModel model);
bool Delete(ProcedureBindingModel model);
int GetNumberOfPages(int userId, int pageSize = 10);
}
}

View File

@ -0,0 +1,11 @@
namespace BeautySalonContracts.SearchModels
{
public class ClientSearchModel
{
public int? Id { get; set; }
public string? ClientLogin { get; set; }
public string? ClientFIO { get; set; }
public string? ClientEmail { get; set; }
public string? ClientPassword { get; set; }
}
}

View File

@ -0,0 +1,10 @@
namespace BeautySalonContracts.SearchModels
{
public class EvaluationSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public int? PageNumber { get; set; }
public int? PageSize { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
public DateTime? OrderDate { get; set; }
public int? ClientId { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace BeautySalonContracts.SearchModels
{
public class ProcedureSearchModel
{
public int? Id { get; set; }
public string? ProcedureName { get; set; }
public int? ClientId { get; set; }
public int? PageNumber { get; set; }
public int? PageSize { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.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);
}
}

View File

@ -0,0 +1,23 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.StoragesContracts
{
public interface IEvaluationStorage
{
List<EvaluationViewModel> GetFullList();
List<EvaluationViewModel> GetFilteredList(EvaluationSearchModel model);
EvaluationViewModel? GetElement(EvaluationSearchModel model);
EvaluationViewModel? Insert(EvaluationBindingModel model);
EvaluationViewModel? Update(EvaluationBindingModel model);
EvaluationViewModel? Delete(EvaluationBindingModel model);
int GetNumberOfPages(int userId, int pageSize);
}
}

View File

@ -0,0 +1,23 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.StoragesContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
int GetNumberOfPages(int userId, int pageSize);
}
}

View File

@ -0,0 +1,22 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.StoragesContracts
{
public interface IProcedureStorage
{
List<ProcedureViewModel> GetFullList();
List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model);
ProcedureViewModel? GetElement(ProcedureSearchModel model);
ProcedureViewModel? Insert(ProcedureBindingModel model);
ProcedureViewModel? Update(ProcedureBindingModel model);
ProcedureViewModel? Delete(ProcedureBindingModel model);
int GetNumberOfPages(int userId, int pageSize);
}
}

View File

@ -0,0 +1,27 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
public int Id { get; set; }
[DisplayName("Логин клиента")]
public string ClientLogin { get; set; } = string.Empty;
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Почта клиента")]
public string ClientEmail { get; set; } = string.Empty;
[DisplayName("Пароль клиента")]
public string ClientPassword { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,24 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.ViewModels
{
public class EvaluationViewModel : IEvaluationModel
{
[DisplayName("Баллы за процедуру")]
public double PointsProcedure { get; set; }
[DisplayName("Баллы за косметику")]
public double PointsCosmetics { get; set; }
public int ClientId { get; set; }
public int Id { get; set; }
public int ProcedureId { get; set; }
public string ProcedureName { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,16 @@
namespace BeautySalonContracts.ViewModels
{
public class OrderCosmeticViewModel
{
public CosmeticViewModel Cosmetic { get; set; } = null!;
public int Count { get; set; }
public OrderCosmeticViewModel() { }
public OrderCosmeticViewModel(CosmeticViewModel cosmetic, int count)
{
Cosmetic = cosmetic;
Count = count;
}
}
}

View File

@ -0,0 +1,16 @@
namespace BeautySalonContracts.ViewModels
{
public class OrderProcedureViewModel
{
public ProcedureViewModel Procedure { get; set; } = null!;
public int Count { get; set; }
public OrderProcedureViewModel() { }
public OrderProcedureViewModel(ProcedureViewModel procedure, int count)
{
Procedure = procedure;
Count = count;
}
}
}

View File

@ -0,0 +1,23 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Дата заказа")]
public DateTime OrderDate { get; set; }
[DisplayName("Сумма")]
public double OrderAmount { get; set; }
public int ClientId { get; set; }
public int Id { get; set; }
public List<OrderServiceViewModel> OrderServices { get; set; } = new();
public List<OrderProcedureViewModel> OrderProcedures { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
namespace BeautySalonContracts.ViewModels
{
public class ProcedureEvaluationViewModel
{
public CosmeticViewModel Cosmetic { get; set; } = null!;
public int Count { get; set; }
public ProcedureEvaluationViewModel() { }
public ProcedureEvaluationViewModel(CosmeticViewModel car, int count)
{
Cosmetic = car;
Count = count;
}
}
}

View File

@ -0,0 +1,26 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.ViewModels
{
public class ProcedureViewModel : IProcedureModel
{
[DisplayName("Наименование процедуры")]
public string ProcedureName { get; set; } = string.Empty;
[DisplayName("Цена процедуры")]
public double ProcedurePrice { get; set; }
public int ClientId { get; set; }
public int Id { get; set; }
public List<ProcedureEvaluationViewModel> ProcedureCosmetics { get; set; } = new();
public List<EvaluationViewModel> ProcedureRatings { get; set; } = new();
}
}

View File

@ -8,7 +8,6 @@
<ItemGroup>
<Folder Include="Enums\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
namespace BeautySalonDataModels.Models
{
public interface IClientModel : IId
{
string ClientLogin { get; }
string ClientFIO { get; }
string ClientEmail { get; }
string ClientPassword { get; }
}
}

View File

@ -0,0 +1,10 @@
namespace BeautySalonDataModels.Models
{
public interface IEvaluationModel : IId
{
double PointsProcedure { get; }
double PointsCosmetics { get; }
int ProcedureId { get; }
int ClientId { get; }
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace BeautySalonDataModels.Models
{
public interface IOrderModel : IId
{
DateTime OrderDate { get; }
double OrderAmount { get; }
int ClientId { get; }
}
}

View File

@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace BeautySalonDataModels.Models
{
public interface IProcedureModel : IId
{
string ProcedureName { get; }
double ProcedurePrice { get; }
int ClientId { get; }
}
}

View File

@ -21,9 +21,4 @@
<ProjectReference Include="..\BeautySalonDataModels\BeautySalonDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Implements\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,97 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
namespace BeautySalonDatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new BeautySalonDatabase();
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 BeautySalonDatabase();
if (model.Id.HasValue)
return context.Clients
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
if (!string.IsNullOrEmpty(model.ClientLogin) &&
!string.IsNullOrEmpty(model.ClientPassword))
return context.Clients
.FirstOrDefault(x =>
x.ClientLogin.Equals(model.ClientLogin) &&
x.ClientPassword.Equals(model.ClientPassword))?
.GetViewModel;
return null;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
}
public List<ClientViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
using var context = new BeautySalonDatabase();
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new BeautySalonDatabase();
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
}
}

View File

@ -0,0 +1,117 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Implements
{
public class EvaluationStorage : IEvaluationStorage
{
public List<EvaluationViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Ratings
.Include(x => x.Procedure)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.LaborsCosts.Where(c => c.StaffMemberId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<EvaluationViewModel> GetFilteredList(EvaluationSearchModel model)
{
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
{
return context.Ratings
.Include(x => x.Procedure)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
{
return context.Ratings
.Include(x => x.Procedure)
.Where(x => x.ClientId == model.ClientId)
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
.Take(model.PageSize.Value)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public EvaluationViewModel? GetElement(EvaluationSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new BeautySalonDatabase();
return context.Ratings
.Include(x => x.Procedure)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public EvaluationViewModel? Insert(EvaluationBindingModel model)
{
var newRating = Evaluation.Create(model);
if (newRating == null)
{
return null;
}
using var context = new BeautySalonDatabase();
context.Ratings.Add(newRating);
context.SaveChanges();
return context.Ratings
.Include(x => x.Procedure)
.FirstOrDefault(x => x.Id == newRating.Id)
?.GetViewModel;
}
public EvaluationViewModel? Update(EvaluationBindingModel model)
{
using var context = new BeautySalonDatabase();
var сosmetic = context.Ratings
.Include(x => x.Procedure)
.FirstOrDefault(x => x.Id == model.Id);
if (сosmetic == null)
{
return null;
}
сosmetic.Update(model);
context.SaveChanges();
return сosmetic.GetViewModel;
}
public EvaluationViewModel? Delete(EvaluationBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Ratings
.Include(x => x.Procedure)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Ratings.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,149 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Orders
.Include(x => x.Services)
.Include(x => x.Procedures)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new BeautySalonDatabase();
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.Orders.Where(c => c.ClientId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new BeautySalonDatabase();
if (model.ClientId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.ThenInclude(x => x.Ratings)
.Where(x => x.ClientId == model.ClientId &&
x.OrderDate >= model.DateFrom && x.OrderDate <= model.DateTo).ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
{
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Where(x => x.ClientId == model.ClientId)
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
.Take(model.PageSize.Value)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<OrderViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new BeautySalonDatabase();
var newOrder = Order.Create(context, model);
if (newOrder == null)
{
return null;
}
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new BeautySalonDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
order.UpdateServices(context, model);
order.UpdateProcedures(context, model);
transaction.Commit();
return order.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,131 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Implements
{
public class ProcedureStorage : IProcedureStorage
{
public ProcedureViewModel? Delete(ProcedureBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Procedures
.Include(x => x.Cosmetics)
.Include(x => x.Orders)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Procedures.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ProcedureViewModel? GetElement(ProcedureSearchModel model)
{
if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue)
{
return null;
}
using var context = new BeautySalonDatabase();
return context.Procedures
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProcedureName) && x.ProcedureName == model.ProcedureName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.Procedures.Where(c => c.ClientId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model)
{
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
{
return context.Procedures
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
{
return context.Procedures
.Where(x => x.ClientId == model.ClientId)
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
.Take(model.PageSize.Value)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Procedures
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ProcedureViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Procedures
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Select(x => x.GetViewModel)
.ToList();
}
public ProcedureViewModel? Insert(ProcedureBindingModel model)
{
using var context = new BeautySalonDatabase();
var newProcedure = Procedure.Create(context, model);
if (newProcedure == null)
{
return null;
}
context.Procedures.Add(newProcedure);
context.SaveChanges();
return newProcedure.GetViewModel;
}
public ProcedureViewModel? Update(ProcedureBindingModel model)
{
using var context = new BeautySalonDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var procedure = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id);
if (procedure == null)
{
return null;
}
procedure.Update(model);
context.SaveChanges();
procedure.UpdateCosmetics(context, model);
transaction.Commit();
return procedure.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,72 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace BeautySalonDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; set; }
[Required]
public string ClientLogin { get; set; } = string.Empty;
[Required]
public string ClientFIO { get; set; } = string.Empty;
[Required]
public string ClientEmail { get; set; } = string.Empty;
[Required]
public string ClientPassword { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Evaluation> Evaluations { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Procedure> Procedures { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientLogin = model.ClientLogin,
ClientFIO = model.ClientFIO,
ClientEmail = model.ClientEmail,
ClientPassword = model.ClientPassword,
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientLogin = model.ClientLogin;
ClientFIO = model.ClientFIO;
ClientEmail = model.ClientEmail;
ClientPassword = model.ClientPassword;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientLogin = ClientLogin,
ClientFIO = ClientFIO,
ClientEmail = ClientEmail,
ClientPassword = ClientPassword,
};
}
}

View File

@ -0,0 +1,69 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Models
{
public class Evaluation : IEvaluationModel
{
public int Id { get; set; }
[Required]
public double PointsProcedure { get; set; }
[Required]
public double PointsCosmetics { get; set; }
[Required]
public int ProcedureId { get; set; }
public int ClientId { get; set; }
public virtual Client Client { get; set; }
public virtual Procedure Procedure { get; set; }
public static Evaluation? Create(EvaluationBindingModel? model)
{
if (model == null)
{
return null;
}
return new Evaluation()
{
Id = model.Id,
PointsProcedure=model.PointsProcedure,
PointsCosmetics=model.PointsCosmetics,
ProcedureId=model.ProcedureId,
ClientId=model.ClientId,
};
}
public void Update(EvaluationBindingModel? model)
{
if (model == null)
{
return;
}
PointsProcedure = model.PointsProcedure;
PointsCosmetics = model.PointsCosmetics;
ProcedureId = model.ProcedureId;
}
public EvaluationViewModel GetViewModel => new()
{
Id = Id,
PointsProcedure=PointsProcedure,
PointsCosmetics=PointsCosmetics,
ProcedureId=ProcedureId,
ClientId=ClientId,
ProcedureName = Procedure.ProcedureName
};
}
}

View File

@ -0,0 +1,142 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; set; }
[Required]
public DateTime OrderDate { get; set; }
[Required]
public double OrderAmount { get; set; }
[Required]
public int ClientId { get; set; }
public virtual Client? Client { get; set; }
private List<OrderServiceViewModel>? _orderServices = null;
private List<OrderProcedureViewModel>? _orderProcedures = null;
[NotMapped]
public List<OrderServiceViewModel> OrderServices
{
get
{
_orderServices ??= Services
.Select(pc => new OrderServiceViewModel(pc.Service.GetViewModel, pc.OrderServiceCount))
.ToList();
return _orderServices;
}
}
[NotMapped]
public List<OrderProcedureViewModel> OrderProcedures
{
get
{
_orderProcedures ??= Procedures
.Select(pc => new OrderProcedureViewModel(pc.Procedure.GetViewModel, pc.OrderProcedureCount))
.ToList();
return _orderProcedures;
}
}
// связь услуги и заказов многие - ко - многим
[ForeignKey("OrderId")]
public virtual List<OrderService> Services { get; set; } = new();
[ForeignKey("OrderId")]
public virtual List<OrderCosmetic> Procedures { get; set; } = new();
public static Order Create(BeautySalonDatabase context, OrderBindingModel model)
{
return new Order()
{
Id = model.Id,
OrderDate = model.OrderDate,
OrderAmount = model.OrderAmount,
Services = model.OrderServices.Select(x => new OrderService()
{
Service = context.Services.First(y => y.Id == x.Service.Id),
OrderServiceCount = x.Count
}).ToList(),
Procedures = model.OrderProcedures.Select(x => new OrderCosmetic()
{
Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id),
OrderProcedureCount = x.Count
}).ToList(),
ClientId = model.ClientId,
};
}
public void Update(OrderBindingModel model)
{
OrderDate = model.OrderDate;
OrderAmount = model.OrderAmount;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
OrderDate = OrderDate,
OrderAmount = OrderAmount,
OrderServices = OrderServices,
OrderProcedures = OrderProcedures,
ClientId = ClientId
};
public void UpdateServices(BeautySalonDatabase context, OrderBindingModel model)
{
var orderServices = context.OrderServices
.Where(x => x.OrderId == model.Id)
.ToList();
context.OrderServices
.RemoveRange(orderServices);
var order = context.Orders.First(x => x.Id == Id);
foreach (var record in model.OrderServices)
{
context.OrderServices.Add(new OrderService
{
Order = order,
Service = context.Services.First(x => x.Id == record.Service.Id),
OrderServiceCount = record.Count
});
context.SaveChanges();
}
_orderServices = null;
}
public void UpdateProcedures(BeautySalonDatabase context, OrderBindingModel model)
{
var orderProcedures = context.OrderProcedures
.Where(x => x.OrderId == model.Id)
.ToList();
context.OrderProcedures
.RemoveRange(orderProcedures);
var order = context.Orders.First(x => x.Id == Id);
foreach (var record in model.OrderProcedures)
{
context.OrderProcedures.Add(new OrderCosmetic
{
Order = order,
Procedure = context.Procedures.First(x => x.Id == record.Procedure.Id),
OrderProcedureCount = record.Count
});
context.SaveChanges();
}
_orderProcedures = null;
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Models
{
public class OrderCosmetic
{
public int Id { get; set; }
[Required]
public int OrderId { get; set; }
[Required]
public int ProcedureId { get; set; }
[Required]
public int OrderProcedureCount { get; set; }
public virtual Order Order { get; set; } = new();
public virtual Procedure Procedure { get; set; } = new();
}
}

View File

@ -0,0 +1,121 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Models
{
public class Procedure : IProcedureModel
{
public int Id { get; set; }
[Required]
public string ProcedureName { get; set; } = string.Empty;
[Required]
public double ProcedurePrice { get; set; }
public int ClientId { get; set; }
public virtual Client Client { get; set; } = null!;
private List<ProcedureCosmeticViewModel>? _procedureCosmetics = null;
[NotMapped]
public List<ProcedureCosmeticViewModel> ProcedureCosmetics
{
get
{
_procedureCosmetics ??= Cosmetics
.Select(pc => new ProcedureCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.ProcedureCosmeticCount))
.ToList();
return _procedureCosmetics;
}
}
// связь процедуры и оценок один - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<Evaluation> Ratings { get; set; } = new();
private List<EvaluationViewModel>? _procedureRatings = null;
[NotMapped]
public List<EvaluationViewModel> ProcedureRatings
{
get
{
_procedureRatings ??= Ratings
.Select(x => x.GetViewModel)
.ToList();
return _procedureRatings;
}
}
// связь процедур и косметки многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<ProcedureCosmetic> Cosmetics { get; set; } = new();
// связь процедур и заказов многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<OrderCosmetic> Orders { get; set; } = new();
public static Procedure Create(BeautySalonDatabase context, ProcedureBindingModel model)
{
return new Procedure()
{
Id = model.Id,
ProcedureName = model.ProcedureName,
ProcedurePrice = model.ProcedurePrice,
Cosmetics = model.ProcedureCosmetics.Select(x => new ProcedureCosmetic()
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
ProcedureCosmeticCount = x.Count
}).ToList(),
ClientId = model.ClientId,
};
}
public void Update(ProcedureBindingModel model)
{
ProcedureName = model.ProcedureName;
ProcedurePrice = model.ProcedurePrice;
}
public ProcedureViewModel GetViewModel => new()
{
Id = Id,
ProcedureName = ProcedureName,
ProcedurePrice = ProcedurePrice,
ProcedureCosmetics = ProcedureCosmetics,
ProcedureRatings = ProcedureRatings,
ClientId = ClientId
};
public void UpdateCosmetics(BeautySalonDatabase context, ProcedureBindingModel model)
{
var procedureCosmetics = context.ProcedureCosmetics
.Where(x => x.ProcedureId == model.Id)
.ToList();
context.ProcedureCosmetics
.RemoveRange(procedureCosmetics);
var procedure = context.Procedures.First(x => x.Id == Id);
foreach (var record in model.ProcedureCosmetics)
{
context.ProcedureCosmetics.Add(new ProcedureCosmetic
{
Procedure = procedure,
Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id),
ProcedureCosmeticCount = record.Count
});
context.SaveChanges();
}
_procedureCosmetics = null;
}
}
}