много че добавил

This commit is contained in:
Milana Ievlewa 2024-04-21 20:33:26 +03:00
parent d9eac56d51
commit 066378286f
45 changed files with 1858 additions and 21 deletions

View File

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

View File

@ -0,0 +1,120 @@
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 CosmeticLogic : ICosmeticLogic
{
private readonly ILogger _logger;
private readonly ICosmeticStorage _cosmeticStorage;
public CosmeticLogic(ILogger<CosmeticLogic> logger, ICosmeticStorage cosmeticStorage)
{
_logger = logger;
_cosmeticStorage = cosmeticStorage;
}
public List<CosmeticViewModel>? ReadList(CosmeticSearchModel? model)
{
_logger.LogInformation("ReadList. CosmeticName: {CosmeticName}. Id: {Id}",
model?.CosmeticName, model?.Id);
var list = model == null ? _cosmeticStorage.GetFullList() :
_cosmeticStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public CosmeticViewModel? ReadElement(CosmeticSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. CosmeticName: {CosmeticName}. Id: {Id}",
model.CosmeticName, model.Id);
var element = _cosmeticStorage.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(CosmeticBindingModel model)
{
CheckModel(model);
if (_cosmeticStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(CosmeticBindingModel model)
{
CheckModel(model);
if (_cosmeticStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(CosmeticBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_cosmeticStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(CosmeticBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.CosmeticName))
{
throw new ArgumentNullException("Нет названия косметики", nameof(model.CosmeticName));
}
if (string.IsNullOrEmpty(model.Brand))
{
throw new ArgumentNullException("Не указан бренд косметики", nameof(model.CosmeticName));
}
if (model.CosmeticPrice <= 0)
{
throw new ArgumentNullException("Цена косметики должна быть больше 0", nameof(model.CosmeticPrice));
}
_logger.LogInformation("Cosmetic. Brand: {Brand}. CosmeticName: {CosmeticName}. CosmeticPrice: {CosmeticPrice}. Id: {Id}",
model.Brand, model.CosmeticName, model.CosmeticPrice, model.Id);
var element = _cosmeticStorage.GetElement(new CosmeticSearchModel
{
CosmeticName = model.CosmeticName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Косметика с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,109 @@
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 LaborCostsLogic : ILaborCostsLogic
{
private readonly ILogger _logger;
private readonly ILaborCostsStorage _laborCostsStorage;
public LaborCostsLogic(ILogger<LaborCostsLogic> logger, ILaborCostsStorage laborCostsStorage)
{
_logger = logger;
_laborCostsStorage = laborCostsStorage;
}
public List<LaborCostsViewModel>? ReadList(LaborCostsSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}",
model?.Id);
var list = model == null ? _laborCostsStorage.GetFullList() :
_laborCostsStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public LaborCostsViewModel? ReadElement(LaborCostsSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}",
model.Id);
var element = _laborCostsStorage.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(LaborCostsBindingModel model)
{
CheckModel(model);
if (_laborCostsStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(LaborCostsBindingModel model)
{
CheckModel(model);
if (_laborCostsStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(LaborCostsBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_laborCostsStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(LaborCostsBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.NumberHours <= 0)
{
throw new ArgumentNullException("Количество часов должно быть больше 0", nameof(model.NumberHours));
}
if (string.IsNullOrEmpty(model.Difficulty))
{
throw new ArgumentNullException("Не указана сложность трудозатраты", nameof(model.Difficulty));
}
_logger.LogInformation("LaborCosts. NumberHours: {NumberHours}. Difficulty: {Difficulty}. Id: {Id}",
model.NumberHours, model.Difficulty, model.Id);
}
}
}

View File

@ -0,0 +1,119 @@
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 ServiceLogic : IServiceLogic
{
private readonly ILogger _logger;
private readonly IServiceStorage _serviceStorage;
public ServiceLogic(ILogger<ServiceLogic> logger, IServiceStorage serviceStorage)
{
_logger = logger;
_serviceStorage = serviceStorage;
}
public List<ServiceViewModel>? ReadList(ServiceSearchModel? model)
{
_logger.LogInformation("ReadList. ServiceName: {ServiceName}. Id: {Id}",
model?.ServiceName, model?.Id);
var list = model == null ? _serviceStorage.GetFullList() :
_serviceStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ServiceViewModel? ReadElement(ServiceSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ServiceName: {ServiceName}. Id: {Id}",
model.ServiceName, model.Id);
var element = _serviceStorage.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(ServiceBindingModel model)
{
CheckModel(model);
if (_serviceStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ServiceBindingModel model)
{
CheckModel(model);
if (_serviceStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ServiceBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_serviceStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ServiceBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ServiceName))
{
throw new ArgumentNullException("Нет названия услуги", nameof(model.ServiceName));
}
if (model.ServicePrice <= 0)
{
throw new ArgumentNullException("Цена услуги должна быть больше 0",
nameof(model.ServicePrice));
}
_logger.LogInformation("Service. ServiceName: {ServiceName}. Cost: {Cost}. Id: {Id}",
model.ServiceName, model.ServicePrice, model.Id);
var element = _serviceStorage.GetElement(new ServiceSearchModel
{
ServiceName = model.ServiceName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Услуга с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,167 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BeautySalonBusinessLogic.BusinessLogics
{
public class StaffMemberLogic : IStaffMemberLogic
{
private readonly int _passwordMaxLength = 25;
private readonly int _passwordMinLength = 6;
private readonly ILogger _logger;
private readonly IStaffMemberStorage _staffMemberStorage;
public StaffMemberLogic(ILogger<StaffMemberLogic> logger, IStaffMemberStorage staffMemberStorage)
{
_logger = logger;
_staffMemberStorage = staffMemberStorage;
}
public bool Create(StaffMemberBindingModel model)
{
CheckModel(model);
if (_staffMemberStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(StaffMemberBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_staffMemberStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public StaffMemberViewModel? ReadElement(StaffMemberSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. StaffMemberLogin: {StaffMemberLogin}. StaffMemberEmail: {StaffMemberEmail} Id: {Id}",
model.StaffMemberLogin, model.StaffMemberEmail, model.Id);
var element = _staffMemberStorage.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<StaffMemberViewModel>? ReadList(StaffMemberSearchModel? model)
{
_logger.LogInformation("ReadElement. StaffMemberLogin: {StaffMemberLogin}. StaffMemberEmail: {StaffMemberEmail} Id: {Id}",
model?.StaffMemberLogin, model?.StaffMemberEmail, model?.Id);
var list = model == null ? _staffMemberStorage.GetFullList() : _staffMemberStorage.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(StaffMemberBindingModel model)
{
CheckModel(model);
if (_staffMemberStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(StaffMemberBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.StaffMemberName))
{
throw new ArgumentNullException("Нет имени сотрудника", nameof(model.StaffMemberLogin));
}
if (string.IsNullOrEmpty(model.StaffMemberSurname))
{
throw new ArgumentNullException("Нет фамилии сотрудника", nameof(model.StaffMemberLogin));
}
if (string.IsNullOrEmpty(model.StaffMemberSpecialty))
{
throw new ArgumentNullException("Нет специальности сотрудника", nameof(model.StaffMemberLogin));
}
if (string.IsNullOrEmpty(model.StaffMemberLogin))
{
throw new ArgumentNullException("Нет логина сотрудника", nameof(model.StaffMemberLogin));
}
if (string.IsNullOrEmpty(model.StaffMemberEmail))
{
throw new ArgumentNullException("Нет почты сотрудника", nameof(model.StaffMemberEmail));
}
if (string.IsNullOrEmpty(model.StaffMemberPassword))
{
throw new ArgumentNullException("Нет пароля сотрудника", nameof(model.StaffMemberPassword));
}
if (string.IsNullOrEmpty(model.StaffMemberPhone))
{
throw new ArgumentNullException("Нет телефона сотрудника", nameof(model.StaffMemberEmail));
}
if (model.StaffMemberPassword.Length < _passwordMinLength)
{
throw new ArgumentNullException("Пароль слишком короткий", nameof(model.StaffMemberPassword));
}
if (model.StaffMemberPassword.Length > _passwordMaxLength)
{
throw new ArgumentNullException("Пароль слишком длинный", nameof(model.StaffMemberPassword));
}
_logger.LogInformation("ReadElement. StaffMemberLogin: {StaffMemberLogin}. StaffMemberEmail: {StaffMemberEmail} Id: {Id}",
model.StaffMemberLogin, model.StaffMemberEmail, model.Id);
var element = _staffMemberStorage.GetElement(new StaffMemberSearchModel
{
StaffMemberEmail = model.StaffMemberEmail
});
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,19 @@
using BeautySalonDataModels;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.BindingModels
{
public class CosmeticBindingModel : ICosmeticModel
{
public int Id { get; set; }
public string CosmeticName { get; set; } = string.Empty;
public string Brand { get; set; } = string.Empty;
public double CosmeticPrice { get; set; }
public int LaborCostId { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.BindingModels
{
public class LaborCostsBindingModel : ILaborCostsModel
{
public int Id { get; set; }
public int NumberHours { get; set; }
public string Difficulty { get; set; } = string.Empty;
public int StaffMemberId { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.BindingModels
{
public class ServiceBindingModel : IServiceModel
{
public int Id { get; set; }
public string ServiceName { get; set; } = string.Empty;
public double ServicePrice { get; set; }
public int StaffMemberId { get; set; }
public Dictionary<int, (ICosmeticModel, int)> ServiceCosmetics { get; set; } = new();
}
}

View File

@ -0,0 +1,21 @@
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.BindingModels
{
public class StaffMemberBindingModel : IStaffMemberModel
{
public int Id { get; set; }
public string StaffMemberName { get; set; } = string.Empty;
public string StaffMemberSurname { get; set; } = string.Empty;
public string StaffMemberSpecialty { get; set; } = string.Empty;
public string StaffMemberLogin { get; set; } = string.Empty;
public string StaffMemberEmail { get; set; } = string.Empty;
public string StaffMemberPassword { get; set; } = string.Empty;
public string StaffMemberPhone { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,16 @@
using System.Collections.Generic;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonContracts.SearchModels;
namespace BeautySalonContracts.BusinessLogicContracts
{
public interface ICosmeticLogic
{
List<CosmeticViewModel>? ReadList(CosmeticSearchModel? model);
CosmeticViewModel? ReadElement(CosmeticSearchModel model);
bool Create(CosmeticBindingModel model);
bool Update(CosmeticBindingModel model);
bool Delete(CosmeticBindingModel 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 ILaborCostsLogic
{
List<LaborCostsViewModel>? ReadList(LaborCostsSearchModel? model);
LaborCostsViewModel? ReadElement(LaborCostsSearchModel model);
bool Create(LaborCostsBindingModel model);
bool Update(LaborCostsBindingModel model);
bool Delete(LaborCostsBindingModel model);
}
}

View File

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

View File

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

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 CosmeticSearchModel
{
public int? Id {get; set; }
public string? CosmeticName { get; set; }
public string? Brand { get; set; }
public int? LaborCostId { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonContracts.SearchModels
{
public class LaborCostsSearchModel
{
public int? Id { get; set; }
public string? Difficulty { get; set; }
public int? StaffMemberId { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace BeautySalonContracts.SearchModels
{
public class ServiceSearchModel
{
public int? Id { get; set; }
public string? ServiceName { get; set; }
public int? StaffMemberId { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace BeautySalonContracts.SearchModels
{
public class StaffMemberSearchModel
{
public int? Id { get; set; }
public string? StaffMemberName { get; set; }
public string? StaffMemberSpecialty { get; set; }
public string? StaffMemberLogin { get; set; }
public string? StaffMemberEmail { get; set; }
public string? StaffMemberPassword { get; set; }
}
}

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 ICosmeticStorage
{
List<CosmeticViewModel> GetFullList();
List<CosmeticViewModel> GetFilteredList(CosmeticSearchModel model);
CosmeticViewModel? GetElement(CosmeticSearchModel model);
CosmeticViewModel? Insert(CosmeticBindingModel model);
CosmeticViewModel? Update(CosmeticBindingModel model);
CosmeticViewModel? Delete(CosmeticBindingModel model);
List<ProcedureViewModel> GetCosmeticProcedures(CosmeticSearchModel model);
}
}

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 ILaborCostsStorage
{
List<LaborCostsViewModel> GetFullList();
List<LaborCostsViewModel> GetFilteredList(LaborCostsSearchModel model);
LaborCostsViewModel? GetElement(LaborCostsSearchModel model);
LaborCostsViewModel? Insert(LaborCostsBindingModel model);
LaborCostsViewModel? Update(LaborCostsBindingModel model);
LaborCostsViewModel? Delete(LaborCostsBindingModel model);
}
}

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 IServiceStorage
{
List<ServiceViewModel> GetFullList();
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
ServiceViewModel? GetElement(ServiceSearchModel model);
ServiceViewModel? Insert(ServiceBindingModel model);
ServiceViewModel? Update(ServiceBindingModel model);
ServiceViewModel? Delete(ServiceBindingModel model);
}
}

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 IStaffMemberStorage
{
List<StaffMemberViewModel> GetFullList();
List<StaffMemberViewModel> GetFilteredList(StaffMemberSearchModel model);
StaffMemberViewModel? GetElement(StaffMemberSearchModel model);
StaffMemberViewModel? Insert(StaffMemberBindingModel model);
StaffMemberViewModel? Update(StaffMemberBindingModel model);
StaffMemberViewModel? Delete(StaffMemberBindingModel model);
}
}

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 CosmeticViewModel : ICosmeticModel
{
public int Id { get; set; }
[DisplayName("Наименование косметики")]
public string CosmeticName { get; set; } = string.Empty;
[DisplayName("Бренд косметики")]
public string Brand { get; set; } = string.Empty;
[DisplayName("Цена косметики")]
public double CosmeticPrice { get; set; }
public int LaborCostId { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace BeautySalonContracts.ViewModels
{
public class CosmeticWithProceduresViewModel
{
public CosmeticViewModel Cosmetic { get; set; } = new();
public List<string> Procedures { get; set; } = new();
}
}

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 LaborCostsViewModel : ILaborCostsModel
{
public int Id { get; set; }
[DisplayName("Количество часов")]
public int NumberHours { get; set; }
[DisplayName("Сложность")]
public string Difficulty{ get; set; } = string.Empty;
public int StaffMemberId { get; set; }
}
}

View File

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

View File

@ -0,0 +1,29 @@
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 ServiceViewModel : IServiceModel
{
public int Id { get; set; }
[DisplayName("Наименование услуги")]
public string ServiceName { get; set; } = string.Empty;
[DisplayName("Цена услуги")]
public double ServicePrice { get; set; }
public int StaffMemberId { get; set; }
[DisplayName("Сотрудник")]
public string StaffMemberName { get; set; } = string.Empty;
public List<ServiceCosmeticViewModel> ServiceCosmetics { get; set; } = new();
}
}

View File

@ -0,0 +1,36 @@
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 StaffMemberViewModel : IStaffMemberModel
{
public int Id { get; set; }
[DisplayName("Имя сотрудника")]
public string StaffMemberName { get; set; } = string.Empty;
[DisplayName("Фамилия сотрудника")]
public string StaffMemberSurname { get; set; } = string.Empty;
[DisplayName("Специальность сотрудника")]
public string StaffMemberSpecialty{ get; set; } = string.Empty;
[DisplayName("Логин сотрудника")]
public string StaffMemberLogin { get; set; } = string.Empty;
[DisplayName("Почта сотрудника")]
public string StaffMemberEmail { get; set; } = string.Empty;
[DisplayName("Пароль сотрудника")]
public string StaffMemberPassword { get; set; } = string.Empty;
[DisplayName("Телефон сотрудника")]
public string StaffMemberPhone { get; set; } = string.Empty;
}
}

View File

@ -6,9 +6,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Enums\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDataModels.Enums
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDataModels.Models
{
public interface ICosmeticModel : IId
{
string CosmeticName { get; }
string Brand { get; }
double CosmeticPrice { get; }
int LaborCostId { get; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDataModels.Models
{
public interface ILaborCostsModel : IId
{
int NumberHours { get; }
string Difficulty { get; }
int StaffMemberId { get; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDataModels.Models
{
public interface IServiceModel : IId
{
string ServiceName { get; }
double ServicePrice { get; }
int StaffMemberId { get; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDataModels.Models
{
public interface IStaffMemberModel : IId
{
string StaffMemberName { get; }
string StaffMemberSurname { get; }
string StaffMemberSpecialty { get; }
string StaffMemberLogin { get; }
string StaffMemberEmail { get; }
string StaffMemberPassword { get; }
string StaffMemberPhone { get; }
}
}

View File

@ -1,7 +1,31 @@
namespace BeautySalonDatabaseImplement
using DocumentFormat.OpenXml.Drawing.Charts;
using Microsoft.EntityFrameworkCore;
using BeautySalonDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement
{
public class BeautySalonDatabase
public class BeautySalonDataBase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<LaborCosts> LaborCosts { set; get; }
public virtual DbSet<Cosmetic> Cosmetics { set; get; }
public virtual DbSet<Service> Services { set; get; }
public virtual DbSet<ServiceCosmetic> ServiceCosmetics { set; get; }
public virtual DbSet<StaffMember> StaffMembers { set; 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,124 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace BeautySalonDatabaseImplement.Implements
{
public class CosmeticStorage : ICosmeticStorage
{
public List<CosmeticViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Cosmetics
.Select(x => x.GetViewModel)
.ToList();
}
public int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.LaborsCosts.Where(c => c.LaborCostsId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<CosmeticViewModel> GetFilteredList(CosmeticSearchModel model)
{
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
{
return context.Cosmetics
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.LaborCostsId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
{
return context.Cosmetics
.Where(x => x.LaborCostsId == model.LaborCostsId)
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
.Take(model.PageSize.Value)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.LaborCostsId.HasValue)
{
return context.Cosmetics
.Where(x => x.LaborCostsId == model.LaborCostsId)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public CosmeticViewModel? GetElement(CosmeticSearchModel model)
{
if (string.IsNullOrEmpty(model.CosmeticName) && !model.Id.HasValue)
{
return null;
}
using var context = new BeautySalonDatabase();
return context.Cosmetics
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CosmeticName) && x.CosmeticName == model.CosmeticName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public CosmeticViewModel? Insert(CosmeticBindingModel model)
{
var newCosmetic = Cosmetic.Create(model);
if (newCosmetic == null)
{
return null;
}
using var context = new BeautySalonDatabase();
context.Cosmetics.Add(newCosmetic);
context.SaveChanges();
return newCosmetic.GetViewModel;
}
public CosmeticViewModel? Update(CosmeticBindingModel model)
{
using var context = new BeautySalonDatabase();
var сosmetic = context.Cosmetics.FirstOrDefault(x => x.Id == model.Id);
if (сosmetic == null)
{
return null;
}
сosmetic.Update(model);
context.SaveChanges();
return сosmetic.GetViewModel;
}
public CosmeticViewModel? Delete(CosmeticBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Cosmetics.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public List<ProcedureViewModel> GetCosmeticProcedures(CosmeticSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new BeautySalonDatabase();
var procedures = context.ProcedureCosmetics
.Where(x => x.CosmeticId == model.Id)
.Select(x => x.Procedure.GetViewModel)
.ToList();
return procedures;
}
}
}

View File

@ -0,0 +1,106 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Implements
{
public class LaborCostsStorage : ILaborCostsStorage
{
public LaborCostsViewModel? Delete(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.LaborsCosts.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.LaborsCosts.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public LaborCostsViewModel? GetElement(LaborCostsSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new BeautySalonDatabase();
return context.LaborsCosts
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.LaborsCosts.Where(c => c.LaborCostsId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<LaborCostsViewModel> GetFilteredList(LaborCostsSearchModel model)
{
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
{
return context.LaborsCosts
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.LaborCostsId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
{
return context.LaborsCosts
.Where(x => x.LaborCostsId == model.LaborCostsId)
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
.Take(model.PageSize.Value)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<LaborCostsViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.LaborsCosts
.Select(x => x.GetViewModel)
.ToList();
}
public LaborCostsViewModel? Insert(LaborCostsBindingModel model)
{
var newLaborCosts = LaborCosts.Create(model);
if (newLaborCosts == null)
{
return null;
}
using var context = new BeautySalonDatabase();
context.LaborsCosts.Add(newLaborCosts);
context.SaveChanges();
return newLaborCosts.GetViewModel;
}
public LaborCostsViewModel? Update(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var laborCosts = context.LaborsCosts.FirstOrDefault(x => x.Id == model.Id);
if (laborCosts == null)
{
return null;
}
laborCosts.Update(model);
context.SaveChanges();
return laborCosts.GetViewModel;
}
}
}

View File

@ -0,0 +1,133 @@
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 ServiceStorage : IServiceStorage
{
public ServiceViewModel? Delete(ServiceBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.Services
.Include(x => x.Cosmetics)
.Include(x => x.Orders)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Services.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ServiceViewModel? GetElement(ServiceSearchModel model)
{
if (string.IsNullOrEmpty(model.ServiceName) && !model.Id.HasValue)
{
return null;
}
using var context = new BeautySalonDatabase();
return context.Services
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) && x.ServiceName == model.ServiceName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.Services.Where(c => c.LaborCostsId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<ServiceViewModel> GetFilteredList(ServiceSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new BeautySalonDatabase();
if (model.LaborCostsId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
return context.Services
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.LaborCostsId == model.LaborCostsId &&
x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.LaborCostsId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue)
{
return context.Services
.Where(x => x.LaborCostsId == model.LaborCostsId)
.Skip(model.PageSize.Value * (model.PageNumber.Value - 1))
.Take(model.PageSize.Value)
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ServiceViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Services
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Select(x => x.GetViewModel)
.ToList();
}
public ServiceViewModel? Insert(ServiceBindingModel model)
{
using var context = new BeautySalonDatabase();
var newService = Service.Create(context, model);
if (newService == null)
{
return null;
}
context.Services.Add(newService);
context.SaveChanges();
return newService.GetViewModel;
}
public ServiceViewModel? Update(ServiceBindingModel model)
{
using var context = new BeautySalonDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var service = context.Services.FirstOrDefault(rec => rec.Id == model.Id);
if (service == null)
{
return null;
}
service.Update(model);
context.SaveChanges();
service.UpdateCosmetics(context, model);
transaction.Commit();
return service.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

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 LaborCostsStorage : ILaborCostsStorage
{
public LaborCostsViewModel? Delete(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var element = context.LaborCostss.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.LaborCostss.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public LaborCostsViewModel? GetElement(LaborCostsSearchModel model)
{
using var context = new BeautySalonDatabase();
if (model.Id.HasValue)
return context.LaborCostss
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
if (!string.IsNullOrEmpty(model.LaborCostsPassword) &&
!string.IsNullOrEmpty(model.LaborCostsLogin))
return context.LaborCostss
.FirstOrDefault(x =>
x.LaborCostsPassword.Equals(model.LaborCostsPassword) &&
x.LaborCostsLogin.Equals(model.LaborCostsLogin))?
.GetViewModel;
return null;
}
public List<LaborCostsViewModel> GetFilteredList(LaborCostsSearchModel model)
{
throw new NotImplementedException();
}
public List<LaborCostsViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.LaborCostss
.Select(x => x.GetViewModel)
.ToList();
}
public LaborCostsViewModel? Insert(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var newLaborCosts = LaborCosts.Create(model);
if (newLaborCosts == null)
{
return null;
}
context.LaborCostss.Add(newLaborCosts);
context.SaveChanges();
return newLaborCosts.GetViewModel;
}
public LaborCostsViewModel? Update(LaborCostsBindingModel model)
{
using var context = new BeautySalonDatabase();
var LaborCosts = context.LaborCostss.FirstOrDefault(x => x.Id == model.Id);
if (LaborCosts == null)
{
return null;
}
LaborCosts.Update(model);
context.SaveChanges();
return LaborCosts.GetViewModel;
}
}
}

View File

@ -0,0 +1,73 @@
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 Cosmetic : ICosmeticModel
{
public int Id { get; set; }
[Required]
public string Brand { get; set; } = string.Empty;
[Required]
public string CosmeticName { get; set; } = string.Empty;
[Required]
public double CosmeticPrice { get; set; }
public int LaborCostId { get; set; }
public virtual LaborCosts LaborCost { get; set; }
//[ForeignKey("CosmeticId")]
//public virtual List<ProcedureCosmetic> Procedures { get; set; } = new();
[ForeignKey("CosmeticId")]
public virtual List<ServiceCosmetic> Services { get; set; } = new();
public static Cosmetic Create(CosmeticBindingModel model)
{
if (model == null)
{
return null;
}
return new Cosmetic()
{
Id = model.Id,
Brand = model.Brand,
CosmeticName = model.CosmeticName,
CosmeticPrice = model.CosmeticPrice,
LaborCostId = model.LaborCostId
};
}
public void Update(CosmeticBindingModel model)
{
if (model == null)
{
return;
}
Brand = model.Brand;
CosmeticName = model.CosmeticName;
CosmeticPrice = model.CosmeticPrice;
LaborCostId = model.LaborCostId;
}
public CosmeticViewModel GetViewModel => new()
{
Id = Id,
Brand = Brand,
CosmeticName = CosmeticName,
CosmeticPrice = CosmeticPrice,
LaborCostId = LaborCostId
};
}
}

View File

@ -0,0 +1,59 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace BeautySalonDatabaseImplement.Models
{
public class LaborCosts : ILaborCostsModel
{
public int Id { get; set; }
[Required]
public int NumberHours { get; set; }
[Required]
public string Difficulty { get; set; } = string.Empty;
public int StaffMemberId { get; set; }
public virtual StaffMember StaffMember { get; set; }
// Связь трудозатрат и услуг один-ко-многим сущностью Cosmetic
public virtual List<Cosmetic> Cosmetics { get; set; } = new();
public static LaborCosts? Create(LaborCostsBindingModel? model)
{
if (model == null)
{
return null;
}
return new LaborCosts()
{
Id = model.Id,
StaffMemberId = model.StaffMemberId,
NumberHours = model.NumberHours,
Difficulty = model.Difficulty
};
}
public void Update(LaborCostsBindingModel? model)
{
if (model == null)
{
return;
}
NumberHours = model.NumberHours;
}
public LaborCostsViewModel GetViewModel => new()
{
Id = Id,
NumberHours = NumberHours
};
}
}

View File

@ -0,0 +1,105 @@
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.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BeautySalonDatabaseImplement.Models
{
public class Service : IServiceModel
{
public int Id {get; set; }
[Required]
public string ServiceName { get; set; } = string.Empty;
[Required]
public double ServicePrice { get; set; }
private List<ServiceCosmeticViewModel>? _serviceCosmetics = null;
[NotMapped]
public List<ServiceCosmeticViewModel> ServiceCosmetics
{
get
{
_serviceCosmetics ??= Cosmetics
.Select(pc => new ServiceCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.ServiceCosmeticCount))
.ToList();
return _serviceCosmetics;
}
}
// связь услуги и косметки многие - ко - многим
[ForeignKey("ServiceId")]
public virtual List<ServiceCosmetic> Cosmetics { get; set; } = new();
// связь услуги и заказов многие - ко - многим
// [ForeignKey("ServiceId")]
//public virtual List<OrderService> Orders { get; set; } = new();
public static Service Create(BeautySalonDataBase context, ServiceBindingModel model)
{
return new Service()
{
Id = model.Id,
ServiceName = model.ServiceName,
ServicePrice = model.ServicePrice,
Cosmetics = model.ServiceCosmetics.Select(x => new ServiceCosmetic()
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
ServiceCosmeticCount = x.Count
}).ToList(),
DateCreate = model.DateCreate,
LaborCostsId = model.LaborCostsId,
LaborCostsId = model.LaborCostsId
};
}
public void Update(ServiceBindingModel model)
{
ServiceName = model.ServiceName;
ServicePrice = model.ServicePrice;
LaborCostsId = model.LaborCostsId;
}
public ServiceViewModel GetViewModel => new()
{
Id = Id,
ServiceName = ServiceName,
ServicePrice = ServicePrice,
ServiceCosmetics = ServiceCosmetics,
DateCreate = DateCreate,
LaborCostsId = LaborCostsId,
};
public void UpdateCosmetics(BeautySalonDatabase context, ServiceBindingModel model)
{
var serviceSosmetics = context.ServiceCosmetics
.Where(x => x.ServiceId == model.Id)
.ToList();
context.ServiceCosmetics
.RemoveRange(serviceSosmetics);
var service = context.Services.First(x => x.Id == Id);
foreach (var record in model.ServiceCosmetics)
{
context.ServiceCosmetics.Add(new ServiceCosmetic
{
Service = service,
Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id),
ServiceCosmeticCount = record.Count
});
context.SaveChanges();
}
_serviceCosmetics = null;
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautySalonDatabaseImplement.Models
{
public class ServiceCosmetic
{
public int Id { get; set; }
[Required]
public int CosmeticId { get; set; }
[Required]
public int ServiceId { get; set; }
[Required]
public int ServiceCosmeticCount { get; set; }
public virtual Cosmetic Cosmetic { get; set; } = new();
public virtual Service Service { get; set; } = new();
}
}

View File

@ -0,0 +1,87 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace BeautySalonDatabaseImplement.Models
{
public class StaffMember : IStaffMemberModel
{
public int Id { get; set; }
[Required]
public string StaffMemberName { get; set; } = string.Empty;
[Required]
public string StaffMemberSurname { get; set; } = string.Empty;
[Required]
public string StaffMemberSpecialty { get; set; } = string.Empty;
[Required]
public string StaffMemberLogin { get; set; } = string.Empty;
[Required]
public string StaffMemberEmail { get; set; } = string.Empty;
[Required]
public string StaffMemberPassword { get; set; } = string.Empty;
[Required]
public string StaffMemberPhone { get; set; } = string.Empty;
[ForeignKey("StaffMemberId")]
public virtual List<LaborCosts> LaborsCosts { get; set; } = new();
[ForeignKey("StaffMemberId")]
public virtual List<Service> Services { get; set; } = new();
public static StaffMember? Create(StaffMemberBindingModel model)
{
if (model == null)
{
return null;
}
return new StaffMember()
{
Id = model.Id,
StaffMemberName = model.StaffMemberName,
StaffMemberSurname = model.StaffMemberSurname,
StaffMemberSpecialty = model.StaffMemberSpecialty,
StaffMemberLogin = model.StaffMemberLogin,
StaffMemberEmail = model.StaffMemberEmail,
StaffMemberPassword = model.StaffMemberPassword,
StaffMemberPhone = model.StaffMemberPhone,
};
}
public void Update(StaffMemberBindingModel model)
{
if (model == null)
{
return;
}
StaffMemberName = model.StaffMemberName;
StaffMemberSurname = model.StaffMemberSurname;
StaffMemberSpecialty = model.StaffMemberSpecialty;
StaffMemberLogin = model.StaffMemberLogin;
StaffMemberEmail = model.StaffMemberEmail;
StaffMemberPassword = model.StaffMemberPassword;
StaffMemberPhone = model.StaffMemberPhone;
}
public StaffMemberViewModel GetViewModel => new()
{
Id = Id,
StaffMemberName = StaffMemberName,
StaffMemberSurname = StaffMemberSurname,
StaffMemberSpecialty = StaffMemberSpecialty,
StaffMemberLogin = StaffMemberLogin,
StaffMemberEmail = StaffMemberEmail,
StaffMemberPassword = StaffMemberPassword,
StaffMemberPhone = StaffMemberPhone,
};
}
}