ломаем все

This commit is contained in:
Milana Ievlewa 2024-05-29 14:21:23 +04:00
parent 97cb5b7ecf
commit 4f48beb8c9
16 changed files with 485 additions and 285 deletions

View File

@ -1,9 +1,5 @@
using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels;
using PrecastConcretePlantBusinessLogic.OfficePackage;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using System;
using System.Collections.Generic;
@ -12,92 +8,147 @@ using System.Text;
using System.Threading.Tasks;
using BeautySalonContracts.BusinessLogicsContracts;
using BeautySalonContracts.StoragesContracts;
using BeautySalonContracts.BindingModels;
namespace BeautySalonBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IProcedureStorage _componentStorage;
private readonly ICosmeticStorage _reinforcedStorage;
private readonly IProcedureStorage _procedureStorage;
private readonly ICosmeticStorage _cosmeticStorage;
private readonly IOrderStorage _orderStorage;
private readonly IServiceStorage _serviceStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ICosmeticStorage reinforcedStorage, IProcedureStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
public ReportLogic(ICosmeticStorage cosmeticStorage, IProcedureStorage procedureStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_reinforcedStorage = reinforcedStorage;
_componentStorage = componentStorage;
_cosmeticStorage = cosmeticStorage;
_procedureStorage = procedureStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
public List<ReportReinforcedComponentViewModel> GetReinforcedComponents()
//Получение процедур по косметике
public List<ReportCosmeticProceduresViewModel> GetCosmeticProcedures()
{
var components = _componentStorage.GetFullList();
var reinforceds = _reinforcedStorage.GetFullList();
var list = new List<ReportReinforcedComponentViewModel>();
foreach (var reinforced in reinforceds)
var procedures = _procedureStorage.GetFullList();
var cosmetics = _cosmeticStorage.GetFullList();
var list = new List<ReportCosmeticProceduresViewModel>();
foreach (var cosmetic in cosmetics)
{
var record = new ReportReinforcedComponentViewModel
var record = new ReportCosmeticProceduresViewModel
{
ReinforcedName = reinforced.ReinforcedName,
Components = new List<(string Component, int Count)>(),
TotalCount = 0
CosmeticName = cosmetic.CosmeticName,
Procedures = new List<string>(),
};
foreach (var component in components)
foreach (var procedure in procedures)
{
if (reinforced.ReinforcedComponents.ContainsKey(component.Id))
// Проверяем соответствие процедуры данному косметическому продукту
if (cosmetic.CosmeticProcedure.Any(cp => cp.Procedure.Id == procedure.Id))
{
record.Components.Add(new(component.ComponentName, reinforced.ReinforcedComponents[component.Id].Item2));
record.TotalCount += reinforced.ReinforcedComponents[component.Id].Item2;
// Добавляем информацию о процедуре в список Procedures
record.Procedures.Add($"{procedure.ProcedureName} - {cosmetic.CosmeticProcedure.Find(cp => cp.Procedure.Id == procedure.Id)}"); // Вы можете использовать нужные вам свойства из CosmeticProcedureViewModel
}
}
list.Add(record);
}
return list;
}
//Получение косметики по процедуре
public List<ReportProcedureCosmeticsViewModel> GetProcedureCosmetics()
{
var procedures = _procedureStorage.GetFullList();
var cosmetics = _cosmeticStorage.GetFullList();
var list = new List<ReportProcedureCosmeticsViewModel>();
foreach (var procedure in procedures)
{
var record = new ReportProcedureCosmeticsViewModel
{
ProcedureName = procedure.ProcedureName,
Cosmetics = new List<(string Cosmetic, int Count)>(),
};
foreach (var cosmetic in cosmetics)
{
if (procedure.CosmeticProcedures.Any(cp => cp.Cosmetic.Id == cosmetic.Id))
{
var cosmeticProcedure = procedure.CosmeticProcedures.Find(cp => cp.Cosmetic.Id == cosmetic.Id);
if (cosmeticProcedure != null)
{
record.Cosmetics.Add((cosmetic.CosmeticName, cosmeticProcedure.Count));
}
}
}
// Вычисляем общее количество для данной процедуры
record.TotalCount = record.Cosmetics.Sum(c => c.Count);
list.Add(record);
}
return list;
}
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
public List<ReportServicesViewModel> GetServices(ReportBindingModel model)
{
List<ReportOrdersViewModel> r = _orderStorage.GetFilteredList(new OrderSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportOrdersViewModel
List<ReportServicesViewModel> r = _serviceStorage.GetFullList()
.Select(x => new ReportServicesViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
ReinforcedName = x.ReinforcedName,
Sum = x.Sum,
Status = x.Status.ToString(),
Cosmetics = x.ServiceCosmetic,
CosmeticName = x.ServiceCosmetic.Cosmetic.Mane
})
.ToList();
return r;
}
public void SaveReinforcedsToWordFile(ReportBindingModel model)
public List<ReportServicesViewModel> GetServices(ReportBindingModel model)
{
List<ReportServicesViewModel> r = _serviceStorage.GetFullList()
.Select(x => new ReportServicesViewModel
{
Id = x.Id,
ProcedureName = x.ServiceProcedure.Procedure.Name,
CosmeticName = x.ServiceCosmetic.Cosmetic.Mane
})
.ToList();
return r;
}
public void SaveCosmeticsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список ЖИ",
Reinforceds = _reinforcedStorage.GetFullList()
Cosmetics = _cosmeticStorage.GetFullList()
});
}
public void SaveReinforcedComponentToExcelFile(ReportBindingModel model)
public void SaveCosmeticProcedureToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список ЖИ",
ReinforcedComponents = GetReinforcedComponents()
CosmeticProcedures = GetCosmeticProcedures()
});
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
public void SaveServicesToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
@ -105,7 +156,7 @@ namespace BeautySalonBusinessLogic.BusinessLogic
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
Services = GetServices(model)
});
}

View File

@ -1,4 +1,5 @@
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Enums;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
@ -8,11 +9,25 @@ namespace BeautySalonContracts.BindingModels
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public double OrderAmount { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
public int ClientId { get; set; }
public List<OrderServiceViewModel> OrderService { get; set; } = new();
public List<OrderCosmeticViewModel> OrderCosmetic { get; set; } = new();
public List<OrderProcedureViewModel> OrderProcedure { get; set; } = new();
public Dictionary<int, string> OrderCosmetics
{
get;
set;
} = new();
public Dictionary<int, string> OrderProcedures
{
get;
set;
} = new();
public Dictionary<int, string> OrderServices
{
get;
set;
} = new();
}
}

View File

@ -8,10 +8,11 @@ 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);
OrderViewModel? ReadElement(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -5,24 +5,41 @@ using System.Text;
using System.Threading.Tasks;
using BeautySalonContracts.ViewModels;
using BeautySalonContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
namespace BeautySalonContracts.BusinessLogicsContracts
{
public interface IReportLogic
{
// Получение списка компонент с указанием, в каких изделиях используются
// Получение списка процедур с указанием, какую косметику использует
List<ReportCosmeticProceduresViewModel> GetCosmeticProcedures();
// Получение списка косметики с указанием, в каких процедурах используется
List<ReportProcedureCosmeticsViewModel> GetProcedureCosmetics();
// Получение списка услуг за определенный период
List<ReportServicesViewModel> GetServices(ReportBindingModel model);
// Получение списка заказов за определенный период
List<ReportViewModel> GetServices(ReportBindingModel model);
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
// Сохранение компонент в файл-Word
void SaveCosmeticsToWordFile(ReportBindingModel model);
// Сохранение компонент с указаеним продуктов в файл-Excel
void SaveCosmeticProceduresToExcelFile(ReportBindingModel model);
// Сохранение процедур по косметике в файл-Word
void SaveCosmeticProceduresToWordFile(ReportBindingModel model);
// Сохранение косметики по процедурам в файл-Word
void SaveProcedureCosmeticsToWordFile(ReportBindingModel model);
// Сохранение заказов в файл-Pdf
// Сохранение процедур с указанием косметики в файл-Excel
void SaveCosmeticProceduresToExcelFile(ReportBindingModel model);
// Сохранение косметики с указанием процедур в файл-Excel
void SaveProcedureCosmeticsToExcelFile(ReportBindingModel model);
// Сохранение услуг в файл-Pdf
void SaveServicesToPdfFile(ReportBindingModel model);
// Сохранение заказов в файл-Pdf
void SaveOrdersToPdfFile(ReportBindingModel model);
}
}

View File

@ -1,4 +1,5 @@
using System;
using BeautySalonDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -9,8 +10,13 @@ namespace BeautySalonContracts.SearchModels
public class OrderSearchModel
{
public int? Id { get; set; }
public DateTime? OrderDate { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public List<OrderStatus>? Statuses { get; set; }
public List<int>? CosmeticIds { get; set; }
public List<int>? PeocedureIds { get; set; }
public List<int>? ServiceIds { get; set; }
}
}

View File

@ -1,7 +1,9 @@
using BeautySalonDataModels.Models;
using BeautySalonDataModels.Enums;
using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,17 +14,35 @@ namespace BeautySalonContracts.ViewModels
{
public int Id { get; set; }
[DisplayName("Дата оформления заказа")]
public DateTime OrderDate { get; set; }
[DisplayName("Стоимость")]
public double OrderAmount { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
public int ClientId { get; set; }
[DisplayName("Клиент")]
public List<OrderServiceViewModel> OrderService { get; set; } = new();
public List<OrderCosmeticViewModel> OrderCosmetic { get; set; } = new();
public List<OrderProcedureViewModel> OrderProcedure { get; set; } = new();
public Dictionary<int, string> OrderCosmetics
{
get;
set;
} = new();
public Dictionary<int, string> OrderProcedures
{
get;
set;
} = new();
public Dictionary<int, string> OrderServices
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.ViewModels
{
public class ReportCosmeticProceduresViewModel
{
public string CosmeticName { get; set; } = string.Empty;
public List<string> Procedures { get; set; } = new();
}
}

View File

@ -10,7 +10,7 @@ namespace PrecastConcretePlantContracts.ViewModels
{
public int Id { get; set; }
public DateTime DateCreate { get; set; }
public string ReinforcedName { get; set; } = string.Empty;
public string ServiceName { get; set; } = string.Empty;
public double Sum { get; set; }
public string Status { get; set; } = string.Empty;
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.ViewModels
{
public class ReportProcedureCosmeticsViewModel
{
public string ProcedureName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<(string Cosmetic, int Count)> Cosmetics { get; set; } = new();
}
}

View File

@ -0,0 +1,17 @@
using BeautySalonContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.ViewModels
{
public class ReportServicesViewModel
{
public int Id { get; set; }
public List<ProcedureViewModel> Procedures{ get; set; }
public List<CosmeticViewModel> Cosmetics { get; set; }
}
}

View File

@ -1,12 +1,18 @@
using System;
using BeautySalonDataModels.Enums;
using System;
using System.Collections.Generic;
namespace BeautySalonDataModels.Models
{
public interface IOrderModel : IId
{
DateTime OrderDate { get; }
double OrderAmount { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
int ClientId { get; }
Dictionary<int, string> OrderCosmetics { get; } //список косметики "участвующей" в заказе
Dictionary<int, string> OrderProcedures{ get; } //список процедур "участвующих" в заказе
Dictionary<int, string> OrderServices { get; } //список услуг "участвующих" в заказе
}
}

View File

@ -18,7 +18,7 @@ namespace BeautySalonDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=ALYONA;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -16,8 +16,6 @@ namespace BeautySalonDatabaseImplement.Implements
{
using var context = new BeautySalonDatabase();
return context.Cosmetics
//.Include(x => x.Procedures)
//.ThenInclude(x => x.Procedure)
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -15,74 +15,6 @@ 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)
.Include(x => x.Cosmetics)
.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)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new BeautySalonDatabase();
if (model.ClientId.HasValue && model.OrderDate.HasValue)
{
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.ClientId == model.ClientId &&
x.OrderDate == model.OrderDate).ToList()
.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();
@ -97,7 +29,44 @@ namespace BeautySalonDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new BeautySalonDatabase();
if (model.ClientId.HasValue)
{
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.ClientId == model.ClientId).ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
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)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new BeautySalonDatabase();
@ -108,7 +77,14 @@ namespace BeautySalonDatabaseImplement.Implements
}
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
@ -136,5 +112,44 @@ namespace BeautySalonDatabaseImplement.Implements
throw;
}
}
public OrderViewModel? Delete(OrderBindingModel model)
{
/*using var context = new BeautySalonDatabase();
var element = context.Orders
.Include(x => x.Services)
.Include(x => x.Procedures)
.Include(x => x.Cosmetics)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;*/
using var context = new BeautySalonDatabase();
var element = context.Orders
.Include(x => x.Services)
.Include(x => x.Procedures)
.Include(x => x.Cosmetics)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element);
context.SaveChanges();
return deletedElement;
}
return null;
}
}
}

View File

@ -1,6 +1,8 @@
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Enums;
using BeautySalonDataModels.Models;
using DocumentFormat.OpenXml.Office2021.DocumentTasks;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@ -25,160 +27,196 @@ namespace BeautySalonDatabaseImplement.Models
public int ClientId { get; set; }
public virtual Client? Client { get; set; }
private List<OrderServiceViewModel>? _orderServices = null;
private List<OrderCosmeticViewModel>? _orderCosmetics = null;
private List<OrderProcedureViewModel>? _orderProcedures = null;
[Required]
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
private Dictionary<int, string>? _orderCosmetics = null;//Это поле для хранения словаря OrderCosmetics.
[NotMapped]
public List<OrderServiceViewModel> OrderServices
public Dictionary<int, string> OrderCosmetics//представляет список косметики, участвующей в заказе. Не присутствует в базе данных.
{
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;
}
}
[NotMapped]
public List<OrderCosmeticViewModel> OrderCosmetics
{
get
{
_orderCosmetics ??= Cosmetics
.Select(pc => new OrderCosmeticViewModel(pc.Cosmetic.GetViewModel))
.ToList();
if (_orderCosmetics == null)
{
_orderCosmetics = Cosmetics
.ToDictionary(recPC => recPC.CosmeticId, recPC => recPC.Cosmetic.CosmeticName);
}
return _orderCosmetics;
}
}
// связь услуги и заказов многие - ко - многим
[ForeignKey("OrderId")]
public virtual List<OrderService> Services { get; set; } = new();
public virtual List<OrderCosmetic> Cosmetics { get; set; } = new();//представляет список косметических товаров для данного заказа.
[ForeignKey("OrderId")]
public virtual List<OrderCosmetic> Cosmetics { get; set; } = new();
private Dictionary<int, string>? _orderProcedures = null;//Это поле для хранения словаря OrderProcedures.
[NotMapped]
public Dictionary<int, string> OrderProcedures//представляет список процедур, участвующих в заказе. Не присутствует в базе данных.
{
get
{
if (_orderProcedures == null)
{
_orderProcedures = Procedures
.ToDictionary(recPC => recPC.ProcedureId, recPC => recPC.Procedure.ProcedureName);
}
return _orderProcedures;
}
}
[ForeignKey("OrderId")]
public virtual List<OrderProcedure> Procedures { get; set; } = new();
public virtual List<OrderProcedure> Procedures { get; set; } = new();//представляет список процедур для данного заказа.
private Dictionary<int, string>? _orderServices = null;//Это поле для хранения словаря OrderServices.
[NotMapped]
public Dictionary<int, string> OrderServices//представляет список процедур, участвующих в заказе. Не присутствует в базе данных.
{
get
{
if (_orderServices == null)
{
_orderServices = Services
.ToDictionary(recPC => recPC.ServiceId, recPC => recPC.Service.ServiceName);
}
return _orderServices;
}
}
[ForeignKey("OrderId")]
public virtual List<OrderService> Services { get; set; } = new();//представляет список процедур для данного заказа.
public static Order_ Create(BeautySalonDatabase context, OrderBindingModel model)
{
return new Order_()
if (model == null)
{
return null;
}
var order = new Order_()
{
Id = model.Id,
OrderDate = model.OrderDate,
OrderAmount = model.OrderAmount,
Services = model.OrderService.Select(x => new OrderService()
{
Service = context.Services.First(y => y.Id == x.Service.Id),
OrderServiceCount = x.Count
}).ToList(),
Procedures = model.OrderProcedure.Select(x => new OrderProcedure()
{
Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id),
OrderProcedureCount = x.Count
}).ToList(),
Cosmetics= model.OrderCosmetic.Select(x => new OrderCosmetic()
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
}).ToList(),
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
ClientId = model.ClientId,
Cosmetics = model.OrderCosmetics.Select(x => new OrderCosmetic
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Key)
}).ToList(),
Procedures = model.OrderProcedures.Select(x => new OrderProcedure
{
Procedure = context.Procedures.First(y => y.Id == x.Key)
}).ToList(),
Services = model.OrderServices.Select(x => new OrderService
{
Service = context.Services.First(y => y.Id == x.Key)
}).ToList()
};
return order;
}
public void Update(OrderBindingModel model)
{
OrderDate = model.OrderDate;
OrderAmount = model.OrderAmount;
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
OrderDate = OrderDate,
OrderAmount = OrderAmount,
OrderService = OrderServices,
OrderProcedure = OrderProcedures,
OrderCosmetic = OrderCosmetics,
ClientId = ClientId
OrderServices = OrderServices,
OrderProcedures = OrderProcedures,
OrderCosmetics = OrderCosmetics,
ClientId = ClientId,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
public void UpdateServices(BeautySalonDatabase context, OrderBindingModel model)
public void UpdateCosmetics(BeautySalonDatabase context, OrderBindingModel model)
{
var orderServices = context.OrderServices
.Where(x => x.OrderId == model.Id)
.ToList();
context.OrderServices
.RemoveRange(orderServices);
var orderCosmetics = context.OrderCosmetics.Where(rec => rec.OrderId == model.Id).ToList();
if (orderCosmetics != null && orderCosmetics.Count > 0)
{ // удалили те, которых нет в модели
context.OrderCosmetics.RemoveRange(orderCosmetics.Where(rec => !model.OrderCosmetics.ContainsKey(rec.CosmeticId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateCosmetic in orderCosmetics)
{
model.OrderCosmetics.Remove(updateCosmetic.CosmeticId);
}
context.SaveChanges();
}
var order = context.Orders.First(x => x.Id == Id);
foreach (var record in model.OrderService)
foreach (var rp in model.OrderCosmetics)
{
context.OrderServices.Add(new OrderService
context.OrderCosmetics.Add(new OrderCosmetic
{
Order = order,
Service = context.Services.First(x => x.Id == record.Service.Id),
OrderServiceCount = record.Count
Cosmetic = context.Cosmetics.First(x => x.Id == rp.Key),
});
context.SaveChanges();
}
_orderServices = null;
_orderCosmetics = null;
}
public void UpdateProcedures(BeautySalonDatabase context, OrderBindingModel model)
{
var orderProcedures = context.OrderProcedures
.Where(x => x.OrderId == model.Id)
.ToList();
context.OrderProcedures
.RemoveRange(orderProcedures);
var orderProcedures = context.OrderProcedures.Where(rec => rec.OrderId == model.Id).ToList();
if (orderProcedures != null && orderProcedures.Count > 0)
{ // удалили те, которых нет в модели
context.OrderProcedures.RemoveRange(orderProcedures.Where(rec => !model.OrderProcedures.ContainsKey(rec.ProcedureId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateProcedure in orderProcedures)
{
model.OrderProcedures.Remove(updateProcedure.ProcedureId);
}
context.SaveChanges();
}
var order = context.Orders.First(x => x.Id == Id);
foreach (var record in model.OrderProcedure)
foreach (var rp in model.OrderProcedures)
{
context.OrderProcedures.Add(new OrderProcedure
{
Order = order,
Procedure = context.Procedures.First(x => x.Id == record.Procedure.Id),
OrderProcedureCount = record.Count
Procedure = context.Procedures.First(x => x.Id == rp.Key),
});
context.SaveChanges();
}
_orderProcedures = null;
}
public void UpdateCosmetics(BeautySalonDatabase context, OrderBindingModel model)
public void UpdateServices(BeautySalonDatabase context, OrderBindingModel model)
{
var orderCosmetic = context.OrderCosmetics
.Where(x => x.OrderId == model.Id)
.ToList();
context.OrderCosmetics
.RemoveRange(orderCosmetic);
var orderServices = context.OrderServices.Where(rec => rec.OrderId == model.Id).ToList();
if (orderServices != null && orderServices.Count > 0)
{ // удалили те, которых нет в модели
context.OrderServices.RemoveRange(orderServices.Where(rec => !model.OrderServices.ContainsKey(rec.ServiceId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateService in orderServices)
{
model.OrderServices.Remove(updateService.ServiceId);
}
context.SaveChanges();
}
var order = context.Orders.First(x => x.Id == Id);
foreach (var record in model.OrderCosmetic)
foreach (var rp in model.OrderServices)
{
context.OrderCosmetics.Add(new OrderCosmetic
context.OrderServices.Add(new OrderService
{
Order = order,
Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id),
Service = context.Services.First(x => x.Id == rp.Key),
});
context.SaveChanges();
}
_orderCosmetics = null;
_orderServices = null;
}
}
}

View File

@ -1,64 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - СlientApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/BeutySalonClientApp.styles.css" asp-append-version="true" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - ClientWebApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ClientWebApp.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<div class="d-flex flex-column">
<a class="navbar-brand fw-weight-bold py-0 px-2" asp-area="" asp-controller="Home" asp-action="Index">Вы Ужасны</a>
<div class="px-2">ClientApp</div>
</div>
<div class="mx-2">
<img src="https://sun9-24.userapi.com/impg/AyVABOovpEhT_XRKJ5-AfQopMZCzJ1w9xOjNzw/XtXFrtPMWhc.jpg?size=1080x1092&quality=95&sign=822391009593062bec0a7ce08018b334&type=album" alt="mdo" width="35" height="35" class="rounded-circle">
</div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Авторизация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Procedure">Процедуры</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Order">Заказы</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Rating">Оценки</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">ClientWebApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - BeutySalonClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2024 - ClientWebApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>