some fixes

This commit is contained in:
Никита Волков 2024-05-04 05:17:11 +04:00
parent 2d19c33ad3
commit 485ed6e322
21 changed files with 428 additions and 50 deletions

View File

@ -92,10 +92,10 @@ namespace BeautyStudioBusinessLogic.BusinessLogics
{
return;
}
if (model.OrderAmount <= 0)
if (model.Sum <= 0)
{
throw new ArgumentNullException("Cумма заказа должна быть больше 0",
nameof(model.OrderAmount));
nameof(model.Sum));
}
}
}

View File

@ -100,13 +100,13 @@ namespace BeautyStudioBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProcedureName));
}
if (model.ProcedurePrice <= 0)
if (model.ProcedureCost <= 0)
{
throw new ArgumentNullException("Цена процедуры должна быть больше 0",
nameof(model.ProcedurePrice));
nameof(model.ProcedureCost));
}
_logger.LogInformation("Procedure. ProcedureName: {ProcedureName}. Cost: {Cost}. Id: {Id}",
model.ProcedureName, model.ProcedurePrice, model.Id);
model.ProcedureName, model.ProcedureCost, model.Id);
var element = _procedureStorage.GetElement(new ProcedureSearchModel
{
ProcedureName = model.ProcedureName

View File

@ -99,13 +99,13 @@ namespace BeautyStudioBusinessLogic.BusinessLogics
throw new ArgumentNullException("Нет названия услуги", nameof(model.ServiceName));
}
if (model.ServicePrice <= 0)
if (model.Sum <= 0)
{
throw new ArgumentNullException("Цена услуги должна быть больше 0",
nameof(model.ServicePrice));
nameof(model.Sum));
}
_logger.LogInformation("Service. ServiceName: {ServiceName}. Cost: {Cost}. Id: {Id}",
model.ServiceName, model.ServicePrice, model.Id);
model.ServiceName, model.Sum, model.Id);
var element = _serviceStorage.GetElement(new ServiceSearchModel
{
ServiceName = model.ServiceName

View File

@ -0,0 +1,159 @@
using BeautyStudioContracts.BindingModels;
using BeautyStudioContracts.BusinessLogicContracts;
using BeautyStudioContracts.SearchModels;
using BeautyStudioContracts.StoragesContracts;
using BeautyStudioContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace BeautyStudioBusinessLogic.BusinessLogics
{
public class StoreKeeperLogic : IStoreKeeperLogic
{
private readonly int _passwordMaxLength = 25;
private readonly int _passwordMinLength = 6;
private readonly ILogger _logger;
private readonly IStoreKeeperStorage _storeKeeperStorage;
public StoreKeeperLogic(ILogger<StoreKeeperLogic> logger, IStoreKeeperStorage storeKeeperStorage)
{
_logger = logger;
_storeKeeperStorage = storeKeeperStorage;
}
public bool Create(StoreKeeperBindingModel model)
{
CheckModel(model);
if (_storeKeeperStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(StoreKeeperBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_storeKeeperStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}",
model.StoreKeeperLogin, model.StoreKeeperEmail, model.Id);
var element = _storeKeeperStorage.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<StoreKeeperViewModel>? ReadList(StoreKeeperSearchModel? model)
{
_logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}",
model?.StoreKeeperLogin, model?.StoreKeeperEmail, model?.Id);
var list = model == null ? _storeKeeperStorage.GetFullList() : _storeKeeperStorage.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(StoreKeeperBindingModel model)
{
CheckModel(model);
if (_storeKeeperStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(StoreKeeperBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.StoreKeeperFIO))
{
throw new ArgumentNullException("Нет имени кладовщика", nameof(model.StoreKeeperLogin));
}
if (string.IsNullOrEmpty(model.StoreKeeperLogin))
{
throw new ArgumentNullException("Нет логина кладовщика", nameof(model.StoreKeeperLogin));
}
if (string.IsNullOrEmpty(model.StoreKeeperEmail))
{
throw new ArgumentNullException("Нет почты кладовщика", nameof(model.StoreKeeperEmail));
}
if (string.IsNullOrEmpty(model.StoreKeeperPassword))
{
throw new ArgumentNullException("Нет пароля кладовщика", nameof(model.StoreKeeperPassword));
}
if (string.IsNullOrEmpty(model.StoreKeeperPhone))
{
throw new ArgumentNullException("Нет телефона кладовщика", nameof(model.StoreKeeperEmail));
}
if (model.StoreKeeperPassword.Length < _passwordMinLength)
{
throw new ArgumentNullException("Пароль слишком короткий", nameof(model.StoreKeeperPassword));
}
if (model.StoreKeeperPassword.Length > _passwordMaxLength)
{
throw new ArgumentNullException("Пароль слишком длинный", nameof(model.StoreKeeperPassword));
}
_logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}",
model.StoreKeeperLogin, model.StoreKeeperEmail, model.Id);
var element = _storeKeeperStorage.GetElement(new StoreKeeperSearchModel
{
StoreKeeperEmail = model.StoreKeeperEmail
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Кладовщик с такой почтой уже есть");
}
}
}
}

View File

@ -13,7 +13,7 @@ namespace BeautyStudioContracts.BindingModels
public int Id { get; set; }
public double Sum { get; set; }
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime DateComplete { get; set; }
public DateTime? DateComplete { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public int ClientId { get; set; }
public int ServiceId { get; set; }

View File

@ -13,6 +13,5 @@ namespace BeautyStudioContracts.BindingModels
public string ServiceName { get; set; } = string.Empty;
public double Sum { get; set; }
public int StaffId { get; set; }
public Dictionary<int, (IProcedureModel, int)> Procedures { get; set; } = new();
}
}

View File

@ -12,6 +12,5 @@ namespace BeautyStudioContracts.BusinessLogicContracts
bool Create(OrderBindingModel model);
bool Delete(OrderBindingModel model);
bool Update(OrderBindingModel model);
int GetNumberOfPages(int userId, int pageSize = 10);
}
}

View File

@ -0,0 +1,20 @@
using BeautyStudioContracts.BindingModels;
using BeautyStudioContracts.SearchModels;
using BeautyStudioContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautyStudioContracts.BusinessLogicContracts
{
public interface IStoreKeeperLogic
{
List<StoreKeeperViewModel>? ReadList(StoreKeeperSearchModel? model);
StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model);
bool Create(StoreKeeperBindingModel model);
bool Update(StoreKeeperBindingModel model);
bool Delete(StoreKeeperBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeautyStudioContracts.ViewModels
{
public class ProcedureCosmeticsViewModel
{
public CosmeticViewModel Cosmetic { get; set; } = null!;
public ProcedureViewModel Procedure { get; set; } = null!;
public int Count { get; set; }
public ProcedureCosmeticsViewModel() { }
public ProcedureCosmeticsViewModel(CosmeticViewModel cosmetic, ProcedureViewModel procedure, int count)
{
Cosmetic = cosmetic;
Procedure = procedure;
Count = count;
}
}
}

View File

@ -24,6 +24,7 @@ namespace BeautyStudioDatabaseImplement
public virtual DbSet<Procedure> Procedures { set; get; }
public virtual DbSet <ProcedureCosmetics> ProcedureCosmetics { set; get; }
public virtual DbSet<Staff> Staffs { set; get; }
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -101,7 +101,7 @@ namespace BeautyStudioDatabaseImplement.Implements
return new();
}
using var context = new BeautyStudioDatabase();
var procedures = context.CosmeticProcedures
var procedures = context.ProcedureCosmetics
.Where(x => x.CosmeticId == model.Id)
.Select(x => x.Procedure.GetViewModel)
.ToList();

View File

@ -118,7 +118,7 @@ namespace BeautyStudioDatabaseImplement.Implements
return new();
}
using var context = new BeautyStudioDatabase();
var cosmetics = context.CosmeticProcedures
var cosmetics = context.ProcedureCosmetics
.Where(x => x.ProcedureId == model.Id)
.Select(x => x.Cosmetic.GetViewModel)
.ToList();

View File

@ -0,0 +1,97 @@
using BeautyStudioContracts.BindingModels;
using BeautyStudioContracts.SearchModels;
using BeautyStudioContracts.StoragesContracts;
using BeautyStudioContracts.ViewModels;
using BeautyStudioDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
namespace BeautyStudioDatabaseImplement.Implements
{
public class StoreKeeperStorage : IStoreKeeperStorage
{
public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model)
{
using var context = new BeautyStudioDatabase();
var element = context.StoreKeepers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.StoreKeepers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model)
{
using var context = new BeautyStudioDatabase();
if (model.Id.HasValue)
return context.StoreKeepers
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
if (!string.IsNullOrEmpty(model.StoreKeeperPassword) &&
!string.IsNullOrEmpty(model.StoreKeeperLogin))
return context.StoreKeepers
.FirstOrDefault(x =>
x.StoreKeeperPassword.Equals(model.StoreKeeperPassword) &&
x.StoreKeeperLogin.Equals(model.StoreKeeperLogin))?
.GetViewModel;
return null;
}
public List<StoreKeeperViewModel> GetFilteredList(StoreKeeperSearchModel model)
{
throw new NotImplementedException();
}
public List<StoreKeeperViewModel> GetFullList()
{
using var context = new BeautyStudioDatabase();
return context.StoreKeepers
.Select(x => x.GetViewModel)
.ToList();
}
public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model)
{
using var context = new BeautyStudioDatabase();
var newStoreKeepers = StoreKeeper.Create(model);
if (newStoreKeepers == null)
{
return null;
}
context.StoreKeepers.Add(newStoreKeepers);
context.SaveChanges();
return newStoreKeepers.GetViewModel;
}
public StoreKeeperViewModel? Update(StoreKeeperBindingModel model)
{
using var context = new BeautyStudioDatabase();
var StoreKeepers = context.StoreKeepers.FirstOrDefault(x => x.Id == model.Id);
if (StoreKeepers == null)
{
return null;
}
StoreKeepers.Update(model);
context.SaveChanges();
return StoreKeepers.GetViewModel;
}
}
}

View File

@ -20,9 +20,9 @@ namespace BeautyStudioDatabaseImplement.Models
[Required]
public string ClientPhone { get; set; } = string.Empty;
[Required]
public string ClientPassword { get; set; } = string.Empty;
//связь один-ко-многим клиента с заказами
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();

View File

@ -28,6 +28,10 @@ namespace BeautyStudioDatabaseImplement.Models
public int LaborCostId { get; set; }
public virtual LaborCost LaborCost { get; set; } = new();
// связь многие-ко-многим косметики с процедурами
[ForeignKey("CosmeticId")]
public virtual List<ProcedureCosmetics> Procedures { get; set; } = new();
public static Cosmetic Create(CosmeticBindingModel model)
{

View File

@ -21,6 +21,8 @@ namespace BeautyStudioDatabaseImplement.Models
public virtual Staff Staff { get; set; }
// связь один-ко-многим трудозатрат с косметикой
[ForeignKey("LaborCostId")]
public virtual List<Cosmetic> Cosmetics { get; set; } = new();
public static LaborCost? Create(LaborCostBindingModel? model)

View File

@ -19,53 +19,36 @@ namespace BeautyStudioDatabaseImplement.Models
public string ProcedureName { get; set; } = string.Empty;
[Required]
public double ProcedurePrice { get; set; }
public double ProcedureCost { get; set; }
[Required]
public double ProcedureDuration { get; set; }
public string ProcedureDescription { get; set; }
[Required]
public double ProcedureDescription { get; set; }
public int ClientId { get; set; }
public virtual Client Client { get; set; } = null!;
// связь процедуры и оценок один - ко - многим
// связь процедур и косметики многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<Evaluation> Evaluations { get; set; } = new();
private List<EvaluationViewModel>? _procedureEvaluations = null;
[NotMapped]
public List<EvaluationViewModel> ProcedureEvaluations
{
get
{
_procedureEvaluations ??= Evaluations
.Select(x => x.GetViewModel)
.ToList();
return _procedureEvaluations;
}
}
public virtual List<ProcedureCosmetics> Cosmetics { get; set; } = new();
// связь процедур и косметки многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<CosmeticProcedure> Cosmetics { get; set; } = new();
private List<CosmeticProcedureViewModel>? _cosmeticProcedures = null;
private List<ProcedureCosmeticsViewModel>? _cosmeticProcedures = null;
[NotMapped]
public List<CosmeticProcedureViewModel> CosmeticProcedures
public List<ProcedureCosmeticsViewModel> CosmeticProcedures
{
get
{
_cosmeticProcedures ??= Cosmetics
.Select(pc => new CosmeticProcedureViewModel(pc.Cosmetic.GetViewModel, pc.Procedure.GetViewModel, pc.ProcedureCosmeticCount))
.Select(pc => new ProcedureCosmeticsViewModel(pc.Cosmetic.GetViewModel, pc.Procedure.GetViewModel, pc.ProcedureCosmeticCount))
.ToList();
return _cosmeticProcedures;
}
}
// связь процедур и заказов многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<OrderCosmetic> Orders { get; set; } = new();
// связь процедур и заказов многие - ко - многим
// связь процедур и услуг многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<ServiceProcedure> Services { get; set; } = new();
@ -76,9 +59,9 @@ namespace BeautyStudioDatabaseImplement.Models
{
Id = model.Id,
ProcedureName = model.ProcedureName,
ProcedurePrice = model.ProcedurePrice,
ProcedureDuration = model.ProcedureDuration,
Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure()
ProcedureCost = model.ProcedureCost,
ProcedureDescription = model.ProcedureDescription,
Cosmetics = model.CosmeticProcedures.Select(x => new CosmeticProcedure()
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
ProcedureCosmeticCount = x.Count
@ -90,17 +73,17 @@ namespace BeautyStudioDatabaseImplement.Models
public void Update(ProcedureBindingModel model)
{
ProcedureName = model.ProcedureName;
ProcedurePrice = model.ProcedurePrice;
ProcedureDuration = model.ProcedureDuration;
ProcedureCost = model.ProcedureCost;
ProcedureDescription = model.ProcedureDescription;
}
public ProcedureViewModel GetViewModel => new()
{
Id = Id,
ProcedureName = ProcedureName,
ProcedurePrice = ProcedurePrice,
ProcedureDuration = ProcedureDuration,
CosmeticProcedures = CosmeticProcedures,
ProcedureCost = ProcedureCost,
ProcedureDescription = ProcedureDescription,
ProcedureCosmetics = CosmeticProcedures,
ClientId = ClientId
};

View File

@ -17,6 +17,9 @@ namespace BeautyStudioDatabaseImplement.Models
[Required]
public int CosmeticId { get; set; }
[Required]
public int ProcedureCosmeticCount { get; set; }
public virtual Procedure Procedure { get; set; } = new();
public virtual Cosmetic Cosmetic { get; set; } = new();

View File

@ -27,6 +27,14 @@ namespace BeautyStudioDatabaseImplement.Models
public int StaffId { get; set; }
public virtual Staff Staff { get; set; }
// связь многие-ко-многим услуг с заказами
[ForeignKey("ServiceId")]
public virtual List<OrderService> Orders { get; set; } = new();
// связь многие-ко-многим услуг с процедурами
[ForeignKey("ServiceId")]
public virtual List<ServiceProcedure> Procedures { get; set; } = new();
public static Service Create(BeautyStudioDatabase context, ServiceBindingModel model)
{
return new Service()

View File

@ -25,12 +25,18 @@ namespace BeautyStudioDatabaseImplement.Models
[Required]
public string StaffPhone { get; set; } = string.Empty;
//связь один-ко-многим с трудозатратами
[ForeignKey("StaffId")]
public virtual List<LaborCost> LaborCost { get; set; } = new();
// связь один-ко-многим с услугами
[ForeignKey("StaffId")]
public virtual List<Service> Services { get; set; } = new();
// связь один-ко-многим с заказами
[ForeignKey("StaffId")]
public virtual List<Order> Orders { get; set; } = new();
public static Staff? Create(StaffBindingModel model)
{

View File

@ -0,0 +1,73 @@
using BeautyStudioContracts.BindingModels;
using BeautyStudioContracts.ViewModels;
using BeautyStudioDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace BeautyStudioDatabaseImplement.Models
{
public class StoreKeeper : IStoreKeeperModel
{
public int Id { get; set; }
[Required]
public string StoreKeeperFIO { get; set; } = string.Empty;
[Required]
public string StoreKeeperEmail { get; set; } = string.Empty;
[Required]
public string StoreKeeperLogin { get; set; } = string.Empty;
[Required]
public string StoreKeeperPassword { get; set; } = string.Empty;
[Required]
public string StoreKeeperPhone { get; set; } = string.Empty;
//связь один-ко-многим кладовщика с косметикой
[ForeignKey("StoreKeeperId")]
public virtual List<Cosmetic> Cosmetics { get; set; } = new();
public static StoreKeeper? Create(StoreKeeperBindingModel model)
{
if (model == null)
{
return null;
}
return new StoreKeeper()
{
Id = model.Id,
StoreKeeperFIO = model.StoreKeeperFIO,
StoreKeeperLogin = model.StoreKeeperLogin,
StoreKeeperEmail = model.StoreKeeperEmail,
StoreKeeperPassword = model.StoreKeeperPassword,
StoreKeeperPhone = model.StoreKeeperPhone,
};
}
public void Update(StoreKeeperBindingModel model)
{
if (model == null)
{
return;
}
StoreKeeperFIO = model.StoreKeeperFIO;
StoreKeeperLogin = model.StoreKeeperLogin;
StoreKeeperEmail = model.StoreKeeperEmail;
StoreKeeperPassword = model.StoreKeeperPassword;
StoreKeeperPhone = model.StoreKeeperPhone;
}
public StoreKeeperViewModel GetViewModel => new()
{
Id = Id,
StoreKeeperFIO = StoreKeeperFIO,
StoreKeeperLogin = StoreKeeperLogin,
StoreKeeperEmail = StoreKeeperEmail,
StoreKeeperPassword = StoreKeeperPassword,
StoreKeeperPhone = StoreKeeperPhone,
};
}
}