1!1!1!1!1!
This commit is contained in:
parent
b03c89593a
commit
cf2ac97d20
@ -6,6 +6,7 @@
|
|||||||
Принят = 0,
|
Принят = 0,
|
||||||
Выполняется = 1,
|
Выполняется = 1,
|
||||||
Готов = 2,
|
Готов = 2,
|
||||||
Выдан = 3
|
Ожидает = 3,
|
||||||
}
|
Выдан = 4
|
||||||
|
}
|
||||||
}
|
}
|
@ -40,22 +40,28 @@ namespace JewelryStore
|
|||||||
services.AddTransient<IStoreStorage, StoreStorage>();
|
services.AddTransient<IStoreStorage, StoreStorage>();
|
||||||
services.AddTransient<IStoreStorage, StoreStorage>();
|
services.AddTransient<IStoreStorage, StoreStorage>();
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<IJewelLogic, JewelLogic>();
|
services.AddTransient<IJewelLogic, JewelLogic>();
|
||||||
services.AddTransient<IStoreLogic, StoreLogic>();
|
services.AddTransient<IStoreLogic, StoreLogic>();
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<IReportLogic, ReportLogic>();
|
services.AddTransient<IReportLogic, ReportLogic>();
|
||||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
services.AddTransient<FormComponent>();
|
services.AddTransient<FormComponent>();
|
||||||
services.AddTransient<FormComponents>();
|
services.AddTransient<FormComponents>();
|
||||||
services.AddTransient<FormCreateOrder>();
|
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
services.AddTransient<FormJewel>();
|
services.AddTransient<FormJewel>();
|
||||||
services.AddTransient<FormJewelComponent>();
|
services.AddTransient<FormJewelComponent>();
|
||||||
services.AddTransient<FormJewels>();
|
services.AddTransient<FormJewels>();
|
||||||
services.AddTransient<FormStores>();
|
services.AddTransient<FormStores>();
|
||||||
services.AddTransient<FormStore>();
|
services.AddTransient<FormStore>();
|
||||||
|
services.AddTransient<FormImplementers>();
|
||||||
|
services.AddTransient<FormImplementer>();
|
||||||
services.AddTransient<FormReportJewelComponents>();
|
services.AddTransient<FormReportJewelComponents>();
|
||||||
services.AddTransient<FormReportOrders>();
|
services.AddTransient<FormReportOrders>();
|
||||||
services.AddTransient<FormReportShop>();
|
services.AddTransient<FormReportShop>();
|
||||||
|
@ -23,105 +23,106 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
|||||||
_implementerStorage = implementerStorage;
|
_implementerStorage = implementerStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(ImplementerBindingModel model)
|
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id);
|
||||||
if (_implementerStorage.Insert(model) == null)
|
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
|
||||||
{
|
if (list == null)
|
||||||
_logger.LogWarning("Insert operation failed");
|
{
|
||||||
return false;
|
_logger.LogWarning("ReadList return null list");
|
||||||
}
|
return null;
|
||||||
return true;
|
}
|
||||||
}
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Delete(ImplementerBindingModel model)
|
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
if (model == null)
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
{
|
||||||
if (_implementerStorage.Delete(model) == null)
|
throw new ArgumentNullException(nameof(model));
|
||||||
{
|
}
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id);
|
||||||
return false;
|
var element = _implementerStorage.GetElement(model);
|
||||||
}
|
if (element == null)
|
||||||
return true;
|
{
|
||||||
}
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
|
public bool Create(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
CheckModel(model);
|
||||||
{
|
if (_implementerStorage.Insert(model) == null)
|
||||||
throw new ArgumentNullException(nameof(model));
|
{
|
||||||
}
|
_logger.LogWarning("Insert operation failed");
|
||||||
_logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}", model.ImplementerFIO, model.Id);
|
return false;
|
||||||
var element = _implementerStorage.GetElement(model);
|
}
|
||||||
if (element == null)
|
return true;
|
||||||
{
|
}
|
||||||
_logger.LogWarning("ReadElement element not found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
public bool Update(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id);
|
CheckModel(model);
|
||||||
var list = (model == null) ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
|
if (_implementerStorage.Update(model) == null)
|
||||||
if (list == null)
|
{
|
||||||
{
|
_logger.LogWarning("Update operation failed");
|
||||||
_logger.LogWarning("ReadList return null list");
|
return false;
|
||||||
return null;
|
}
|
||||||
}
|
return true;
|
||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
}
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Update(ImplementerBindingModel model)
|
public bool Delete(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model, false);
|
||||||
if (_implementerStorage.Update(model) == null)
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
{
|
if (_implementerStorage.Delete(model) == null)
|
||||||
_logger.LogWarning("Update operation failed");
|
{
|
||||||
return false;
|
_logger.LogWarning("Delete operation failed");
|
||||||
}
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
|
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
if (!withParams)
|
if (!withParams)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (model.WorkExperience < 0)
|
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience));
|
throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO));
|
||||||
}
|
}
|
||||||
if (model.Qualification < 0)
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification));
|
throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.Password))
|
if (model.WorkExperience < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO));
|
throw new ArgumentNullException("Стаж должен быть больше 0", nameof(model.WorkExperience));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
if (model.Qualification < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO));
|
throw new ArgumentNullException("Квалификация должна быть положительной", nameof(model.Qualification));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO);
|
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}.Password:{Password}.WorkExperience:{WorkExperience}.Qualification:{Qualification}.Id: { Id}",
|
||||||
var element = _implementerStorage.GetElement(new ImplementerSearchModel
|
model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id);
|
||||||
{
|
var element = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||||
ImplementerFIO = model.ImplementerFIO,
|
{
|
||||||
});
|
ImplementerFIO = model.ImplementerFIO
|
||||||
if (element != null && element.Id != model.Id)
|
});
|
||||||
{
|
if (element != null && element.Id != model.Id)
|
||||||
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
|
{
|
||||||
}
|
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,153 +1,194 @@
|
|||||||
using JewelryStoreContracts.BindingModels;
|
using JewelryStoreDataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using JewelryStoreContracts.BindingModels;
|
||||||
|
using JewelryStoreContracts.BusinessLogicsContracts;
|
||||||
|
using JewelryStoreContracts.SearchModels;
|
||||||
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
|
using JewelryStoreContracts.ViewModels;
|
||||||
|
using JewelryStoreContracts.BindingModels;
|
||||||
using JewelryStoreContracts.BusinessLogicsContracts;
|
using JewelryStoreContracts.BusinessLogicsContracts;
|
||||||
using JewelryStoreContracts.SearchModels;
|
using JewelryStoreContracts.SearchModels;
|
||||||
using JewelryStoreContracts.StoragesContracts;
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
using JewelryStoreContracts.StoragesModels;
|
|
||||||
using JewelryStoreContracts.ViewModels;
|
using JewelryStoreContracts.ViewModels;
|
||||||
using JewelryStoreDataModels.Enums;
|
using JewelryStoreDataModels.Enums;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace JewelryStoreBusinessLogic.BusinessLogics
|
namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class OrderLogic : IOrderLogic
|
public class OrderLogic : IOrderLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
private readonly IStoreStorage _shopStorage;
|
static readonly object _locker = new object();
|
||||||
|
private readonly IShopStorage _shopStorage;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IStoreStorage shopStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
_shopStorage = shopStorage;
|
_shopStorage = shopStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
if (model == null)
|
||||||
if (model.Status != OrderStatus.Неизвестен) return false;
|
|
||||||
model.Status = OrderStatus.Принят;
|
|
||||||
if (_orderStorage.Insert(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Insert operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
|
||||||
{
|
|
||||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
|
model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
|
||||||
|
var element = _orderStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||||
|
model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
|
||||||
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Неизвестен)
|
||||||
|
return false;
|
||||||
|
model.Status = OrderStatus.Принят;
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
lock (_locker)
|
||||||
|
{
|
||||||
|
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return ChangeStatus(model, OrderStatus.Готов);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
lock (_locker)
|
||||||
|
{
|
||||||
|
model = FillOrderBindingModel(model);
|
||||||
|
if (model.Status != OrderStatus.Готов && model.Status != OrderStatus.Ожидает)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-Выдан.", model.Status);
|
||||||
|
throw new InvalidOperationException($"Невозможно приствоить статус выдан заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
||||||
|
{
|
||||||
|
JewelId = model.JewelId,
|
||||||
|
Count = model.Count
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
if (model.Status == OrderStatus.Готов || model.Status == OrderStatus.Ожидает)
|
||||||
|
{
|
||||||
|
model.Status = OrderStatus.Ожидает;
|
||||||
|
return UpdateOrder(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.Status = OrderStatus.Выдан;
|
||||||
|
return UpdateOrder(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (model.Count <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Колличество украшения в заказе не может быть меньше 1", nameof(model.Count));
|
||||||
|
}
|
||||||
|
if (model.Sum <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum));
|
||||||
|
}
|
||||||
|
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
|
||||||
|
{
|
||||||
|
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Jewel. JewelId:{JewelId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
||||||
|
model.JewelId, model.Count, model.Sum, model.Id);
|
||||||
|
}
|
||||||
|
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
||||||
|
{
|
||||||
|
model = FillOrderBindingModel(model);
|
||||||
|
|
||||||
|
if (requiredStatus - model.Status == 1)
|
||||||
|
{
|
||||||
|
model.Status = requiredStatus;
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
return UpdateOrder(model);
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||||
|
throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderBindingModel FillOrderBindingModel(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
});
|
});
|
||||||
if (order == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(order));
|
throw new InvalidOperationException(nameof(element));
|
||||||
}
|
}
|
||||||
if (!_shopStorage.RestockingShops(new SupplyBindingModel
|
model.Id = element.Id;
|
||||||
|
model.DateCreate = element.DateCreate;
|
||||||
|
model.JewelId = element.JewelId;
|
||||||
|
model.DateImplement = element.DateImplement;
|
||||||
|
model.ClientId = element.ClientId;
|
||||||
|
model.Status = element.Status;
|
||||||
|
model.Count = element.Count;
|
||||||
|
model.Sum = element.Sum;
|
||||||
|
if (!model.ImplementerId.HasValue)
|
||||||
{
|
{
|
||||||
JewelId = order.JewelId,
|
model.ImplementerId = element.ImplementerId;
|
||||||
Count = order.Count
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Недостаточно места");
|
|
||||||
}
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
model.Status = OrderStatus.Выдан;
|
private bool UpdateOrder(OrderBindingModel model)
|
||||||
model.DateImplement = DateTime.Now;
|
{
|
||||||
_orderStorage.Update(model);
|
if (_orderStorage.Update(model) == null)
|
||||||
return true;
|
{
|
||||||
}
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
model.Status = newStatus;
|
}
|
||||||
model.DateCreate = vmodel.DateCreate;
|
_logger.LogWarning("Update operation sucsess");
|
||||||
if (model.DateImplement == null)
|
return true;
|
||||||
{
|
}
|
||||||
model.DateImplement = vmodel.DateImplement;
|
}
|
||||||
}
|
}
|
||||||
if (vmodel.ImplementerId.HasValue)
|
|
||||||
{
|
|
||||||
model.ImplementerId = vmodel.ImplementerId;
|
|
||||||
}
|
|
||||||
model.JewelId = vmodel.JewelId;
|
|
||||||
model.Sum = vmodel.Sum;
|
|
||||||
model.Count = vmodel.Count;
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
model.Status--;
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
model.DateImplement = DateTime.Now;
|
|
||||||
return StatusUpdate(model, OrderStatus.Готов);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool FinishOrder(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
return StatusUpdate(model, OrderStatus.Выдан);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
|
||||||
if (list == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadList return null list");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool CheckModel(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
if (model.Count <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
|
||||||
}
|
|
||||||
if (model.Sum <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum));
|
|
||||||
}
|
|
||||||
if (model.DateCreate > model.DateImplement)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
|
||||||
var element = _orderStorage.GetElement(model);
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadElement element not found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,137 +4,183 @@ using JewelryStoreContracts.SearchModels;
|
|||||||
using JewelryStoreContracts.ViewModels;
|
using JewelryStoreContracts.ViewModels;
|
||||||
using JewelryStoreDataModels.Enums;
|
using JewelryStoreDataModels.Enums;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using JewelryStoreContracts.BindingModels;
|
||||||
using System.Collections.Generic;
|
using JewelryStoreContracts.BusinessLogicsContracts;
|
||||||
using System.Linq;
|
using JewelryStoreContracts.SearchModels;
|
||||||
using System.Text;
|
using JewelryStoreContracts.ViewModels;
|
||||||
using System.Threading.Tasks;
|
using JewelryStoreDataModels.Enums;
|
||||||
|
|
||||||
namespace JewelryStoreBusinessLogic.BusinessLogics
|
namespace JewelryStoreBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class WorkModeling : IWorkProcess
|
public class WorkModeling : IWorkProcess
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly Random _rnd;
|
private readonly Random _rnd;
|
||||||
|
|
||||||
private IOrderLogic? _orderLogic;
|
private IOrderLogic? _orderLogic;
|
||||||
|
|
||||||
public WorkModeling(ILogger<WorkModeling> logger)
|
public WorkModeling(ILogger<WorkModeling> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_rnd = new Random(1000);
|
_rnd = new Random(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
|
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
|
||||||
{
|
{
|
||||||
_orderLogic = orderLogic;
|
_orderLogic = orderLogic;
|
||||||
var implementers = implementerLogic.ReadList(null);
|
var implementers = implementerLogic.ReadList(null);
|
||||||
if (implementers == null)
|
if (implementers == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("DoWork. Implementers is null");
|
_logger.LogWarning("DoWork. Implementers is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выдан });
|
||||||
|
int count = _orderLogic.ReadList(null).Count;
|
||||||
|
if (orders == null || count == orders.Count)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
orders = _orderLogic.ReadList(null);
|
||||||
|
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||||
|
foreach (var implementer in implementers)
|
||||||
|
{
|
||||||
|
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } });
|
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
|
||||||
if (orders == null || orders.Count == 0)
|
{
|
||||||
{
|
if (_orderLogic == null || implementer == null)
|
||||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await DeliverWaitingOrder(implementer);
|
||||||
|
await RunOrderInWork(implementer);
|
||||||
|
|
||||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
foreach (var order in orders)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
||||||
|
// пытаемся назначить заказ на исполнителя
|
||||||
|
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = order.Id,
|
||||||
|
ImplementerId = implementer.Id
|
||||||
|
});
|
||||||
|
// делаем работу
|
||||||
|
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
|
||||||
|
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||||
|
_orderLogic.FinishOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = order.Id
|
||||||
|
});
|
||||||
|
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id });
|
||||||
|
}
|
||||||
|
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error try get work");
|
||||||
|
}
|
||||||
|
// заканчиваем выполнение имитации в случае иной ошибки
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error while do work");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
// отдыхаем
|
||||||
|
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var implementer in implementers)
|
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||||
{
|
{
|
||||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
if (_orderLogic == null || implementer == null)
|
||||||
}
|
{
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||||
|
{
|
||||||
|
ImplementerId = implementer.Id,
|
||||||
|
Status = OrderStatus.Выполняется
|
||||||
|
}));
|
||||||
|
if (runOrder == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
|
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
||||||
{
|
// доделываем работу
|
||||||
if (_orderLogic == null || implementer == null)
|
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
||||||
{
|
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
|
||||||
return;
|
_orderLogic.FinishOrder(new OrderBindingModel
|
||||||
}
|
{
|
||||||
await RunOrderInWork(implementer, orders);
|
Id = runOrder.Id
|
||||||
|
});
|
||||||
|
_orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id });
|
||||||
|
// отдыхаем
|
||||||
|
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
|
}
|
||||||
|
// заказа может не быть, просто игнорируем ошибку
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error try get work");
|
||||||
|
}
|
||||||
|
// а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error while do work");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await Task.Run(() =>
|
private async Task DeliverWaitingOrder(ImplementerViewModel implementer)
|
||||||
{
|
{
|
||||||
foreach (var order in orders)
|
if (_orderLogic == null || implementer == null)
|
||||||
{
|
{
|
||||||
try
|
return;
|
||||||
{
|
}
|
||||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel
|
||||||
|
{
|
||||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
ImplementerId = implementer.Id,
|
||||||
{
|
Status = OrderStatus.Ожидает
|
||||||
Id = order.Id,
|
}));
|
||||||
ImplementerId = implementer.Id
|
if (waitingOrders == null || waitingOrders.Count == 0)
|
||||||
});
|
{
|
||||||
|
return;
|
||||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
|
}
|
||||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
_logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count);
|
||||||
|
foreach (var waitingOrder in waitingOrders)
|
||||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
{
|
||||||
{
|
try
|
||||||
Id = order.Id
|
{
|
||||||
});
|
_logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id);
|
||||||
|
var res = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
{
|
||||||
}
|
Id = waitingOrder.Id
|
||||||
|
});
|
||||||
catch (InvalidOperationException ex)
|
}
|
||||||
{
|
catch (ArgumentException ex)
|
||||||
_logger.LogWarning(ex, "Error try get work");
|
{
|
||||||
}
|
_logger.LogWarning(ex, "DeliverWaitingOrder. Fault");
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error while do work");
|
_logger.LogWarning(ex, "Error try deliver order");
|
||||||
throw;
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
});
|
_logger.LogError(ex, "Error while do work");
|
||||||
}
|
throw;
|
||||||
|
}
|
||||||
private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
|
}
|
||||||
{
|
}
|
||||||
if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
|
}
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется));
|
|
||||||
if (runOrder == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
|
||||||
|
|
||||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
|
||||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
|
|
||||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
|
||||||
{
|
|
||||||
Id = runOrder.Id
|
|
||||||
});
|
|
||||||
|
|
||||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (InvalidOperationException ex)
|
|
||||||
{
|
|
||||||
_logger.LogWarning(ex, "Error try get work");
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error while do work");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,6 @@ namespace JewelryStoreContracts.BusinessLogicsContracts
|
|||||||
{
|
{
|
||||||
public interface IWorkProcess
|
public interface IWorkProcess
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Запуск работ
|
|
||||||
/// </summary>
|
|
||||||
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,87 +13,72 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public class ImplementerStorage : IImplementerStorage
|
public class ImplementerStorage : IImplementerStorage
|
||||||
{
|
{
|
||||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
public List<ImplementerViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
using var context = new JewelryStoreDatabase();
|
||||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
return context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||||
if (res != null)
|
}
|
||||||
{
|
|
||||||
context.Implementers.Remove(res);
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
return res?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new JewelryStoreDatabase();
|
||||||
|
return context.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
if (model.Id.HasValue)
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
{
|
{
|
||||||
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue)
|
||||||
}
|
{
|
||||||
if (model.ImplementerFIO != null && model.Password != null)
|
return null;
|
||||||
{
|
}
|
||||||
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)&&x.Password.Equals(model.Password))
|
using var context = new JewelryStoreDatabase();
|
||||||
?.GetViewModel;
|
return context.Implementers.FirstOrDefault(x =>
|
||||||
}
|
(!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) ||
|
||||||
if (model.ImplementerFIO != null)
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
{
|
?.GetViewModel;
|
||||||
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
}
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
var newImplementer = Implementer.Create(model);
|
||||||
{
|
if (newImplementer == null)
|
||||||
return new();
|
{
|
||||||
}
|
return null;
|
||||||
if (model.Id.HasValue)
|
}
|
||||||
{
|
using var context = new JewelryStoreDatabase();
|
||||||
var res = GetElement(model);
|
context.Implementers.Add(newImplementer);
|
||||||
return res != null ? new() { res } : new();
|
context.SaveChanges();
|
||||||
}
|
return newImplementer.GetViewModel;
|
||||||
if (model.ImplementerFIO != null)
|
}
|
||||||
{
|
|
||||||
using var context = new JewelryStoreDatabase();
|
|
||||||
return context.Implementers.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
|
||||||
.Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFullList()
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
using var context = new JewelryStoreDatabase();
|
||||||
return context.Implementers.Select(x => x.GetViewModel).ToList();
|
var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
}
|
if (implementer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
implementer.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return implementer.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
using var context = new JewelryStoreDatabase();
|
||||||
var res = Implementer.Create(model);
|
var implementer = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (res != null)
|
if (implementer != null)
|
||||||
{
|
{
|
||||||
context.Implementers.Add(res);
|
context.Implementers.Remove(implementer);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
return implementer.GetViewModel;
|
||||||
|
}
|
||||||
return res?.GetViewModel;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new JewelryStoreDatabase();
|
|
||||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
res.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
return res?.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,46 +17,34 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
using var context = new JewelryStoreDatabase();
|
||||||
return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(y => y.Implementer).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue ||!model.Id.HasValue)
|
using var context = new JewelryStoreDatabase();
|
||||||
{
|
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
|
||||||
var result = GetElement(model);
|
{
|
||||||
return result != null ? new() { result } : new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new JewelryStoreDatabase();
|
return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).Where(x =>
|
||||||
IQueryable<Order>? queryWhere = null;
|
(model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) ||
|
||||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
(model.ClientId.HasValue && x.ClientId == model.ClientId) ||
|
||||||
{
|
(model.Status.HasValue && x.Status == model.Status))
|
||||||
queryWhere = context.Orders.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate.Date <= model.DateTo);
|
.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
else if (model.Statuses != null)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status));
|
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
|
||||||
}
|
{
|
||||||
else if (model.ClientId.HasValue)
|
return new();
|
||||||
{
|
}
|
||||||
queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId);
|
using var context = new JewelryStoreDatabase();
|
||||||
}
|
return context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x =>
|
||||||
else
|
(model.Id.HasValue && x.Id == model.Id) ||
|
||||||
{
|
(model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))
|
||||||
return new();
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
return queryWhere.Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
}
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new JewelryStoreDatabase();
|
|
||||||
return AccessJewelStorage(context.Orders.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x =>(model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) &&
|
|
||||||
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || model.Id.HasValue && x.Id == model.Id)?.GetViewModel, context);
|
|
||||||
}
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
|
||||||
{
|
{
|
||||||
var newOrder = Order.Create(model);
|
var newOrder = Order.Create(model);
|
||||||
if (newOrder == null)
|
if (newOrder == null)
|
||||||
@ -71,15 +59,15 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
using var context = new JewelryStoreDatabase();
|
||||||
var order = context.Orders.Include(x => x.Jewel).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id);
|
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(context, model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessJewelStorage(order.GetViewModel, context);
|
return order.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new JewelryStoreDatabase();
|
using var context = new JewelryStoreDatabase();
|
||||||
|
@ -25,6 +25,7 @@ namespace JewelryStoreDatabaseImplement
|
|||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
public virtual DbSet<Store> Shops { get; set; }
|
public virtual DbSet<Store> Shops { get; set; }
|
||||||
public virtual DbSet<StoreJewels> ShopJewels { get; set; }
|
public virtual DbSet<StoreJewels> ShopJewels { get; set; }
|
||||||
|
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,64 +4,64 @@
|
|||||||
|
|
||||||
namespace JewelryStoreDatabaseImplement.Migrations
|
namespace JewelryStoreDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class AddImplementer : Migration
|
public partial class implementors : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.AddColumn<int>(
|
migrationBuilder.AddColumn<int>(
|
||||||
name: "ImplementerId",
|
name: "ImplementerId",
|
||||||
table: "Orders",
|
table: "Orders",
|
||||||
type: "int",
|
type: "int",
|
||||||
nullable: true);
|
nullable: true);
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Implementers",
|
name: "Implementers",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
||||||
Qualification = table.Column<int>(type: "int", nullable: false)
|
Qualification = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Implementers", x => x.Id);
|
table.PrimaryKey("PK_Implementers", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Orders_ImplementerId",
|
name: "IX_Orders_ImplementerId",
|
||||||
table: "Orders",
|
table: "Orders",
|
||||||
column: "ImplementerId");
|
column: "ImplementerId");
|
||||||
|
|
||||||
migrationBuilder.AddForeignKey(
|
migrationBuilder.AddForeignKey(
|
||||||
name: "FK_Orders_Implementers_ImplementerId",
|
name: "FK_Orders_Implementers_ImplementerId",
|
||||||
table: "Orders",
|
table: "Orders",
|
||||||
column: "ImplementerId",
|
column: "ImplementerId",
|
||||||
principalTable: "Implementers",
|
principalTable: "Implementers",
|
||||||
principalColumn: "Id");
|
principalColumn: "Id");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DropForeignKey(
|
migrationBuilder.DropForeignKey(
|
||||||
name: "FK_Orders_Implementers_ImplementerId",
|
name: "FK_Orders_Implementers_ImplementerId",
|
||||||
table: "Orders");
|
table: "Orders");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Implementers");
|
name: "Implementers");
|
||||||
|
|
||||||
migrationBuilder.DropIndex(
|
migrationBuilder.DropIndex(
|
||||||
name: "IX_Orders_ImplementerId",
|
name: "IX_Orders_ImplementerId",
|
||||||
table: "Orders");
|
table: "Orders");
|
||||||
|
|
||||||
migrationBuilder.DropColumn(
|
migrationBuilder.DropColumn(
|
||||||
name: "ImplementerId",
|
name: "ImplementerId",
|
||||||
table: "Orders");
|
table: "Orders");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using JewelryStoreDatabaseImplement;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using JewelryStoreDatabaseImplement;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
|||||||
b.ToTable("Components");
|
b.ToTable("Components");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ImplementerFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("Qualification")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("WorkExperience")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Implementers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -87,6 +114,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
|||||||
b.Property<DateTime?>("DateImplement")
|
b.Property<DateTime?>("DateImplement")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int?>("ImplementerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("JewelId")
|
b.Property<int>("JewelId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
@ -100,6 +130,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("ClientId");
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
|
b.HasIndex("ImplementerId");
|
||||||
|
|
||||||
b.HasIndex("JewelId");
|
b.HasIndex("JewelId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
@ -212,6 +244,10 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer")
|
||||||
|
.WithMany("Order")
|
||||||
|
.HasForeignKey("ImplementerId");
|
||||||
|
|
||||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("JewelId")
|
.HasForeignKey("JewelId")
|
||||||
@ -220,6 +256,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Client");
|
b.Navigation("Client");
|
||||||
|
|
||||||
|
b.Navigation("Implementer");
|
||||||
|
|
||||||
b.Navigation("Jewel");
|
b.Navigation("Jewel");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -271,6 +309,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
|||||||
b.Navigation("JewelComponents");
|
b.Navigation("JewelComponents");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Order");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Components");
|
b.Navigation("Components");
|
||||||
|
@ -14,77 +14,81 @@ namespace JewelryStoreDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
|
||||||
public int JewelId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
|
||||||
[Required]
|
|
||||||
public double Sum { get; set; }
|
|
||||||
[Required]
|
|
||||||
public OrderStatus Status { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int ClientId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public DateTime DateCreate { get; set; }
|
|
||||||
public DateTime? DateImplement { get; set; }
|
|
||||||
public Jewel Jewel { get; set; }
|
|
||||||
public Client Client { get; set; }
|
|
||||||
public int? ImplementerId { get; private set; }
|
|
||||||
public Implementer? Implementer { get; set; }
|
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ClientId { get; private set; }
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public virtual Client Client { get; private set; } = new();
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Order()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
JewelId = model.JewelId,
|
|
||||||
ClientId = model.ClientId,
|
|
||||||
ImplementerId = model.ImplementerId,
|
|
||||||
Count = model.Count,
|
|
||||||
Sum = model.Sum,
|
|
||||||
Status = model.Status,
|
|
||||||
DateCreate = model.DateCreate,
|
|
||||||
DateImplement = model.DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void Update(OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Status = model.Status;
|
|
||||||
ImplementerId = model.ImplementerId;
|
|
||||||
DateImplement = model.DateImplement;
|
|
||||||
}
|
|
||||||
public OrderViewModel GetViewModel
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
using var context = new JewelryStoreDatabase();
|
|
||||||
return new OrderViewModel
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
JewelId = JewelId,
|
|
||||||
ClientId = ClientId,
|
|
||||||
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
|
||||||
ImplementerId = ImplementerId,
|
|
||||||
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
|
|
||||||
JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty,
|
|
||||||
Count = Count,
|
|
||||||
Sum = Sum,
|
|
||||||
Status = Status,
|
|
||||||
DateCreate = DateCreate,
|
|
||||||
DateImplement = DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
[Required]
|
||||||
}
|
public int JewelId { get; private set; }
|
||||||
|
|
||||||
|
public virtual Jewel Jewel { get; set; } = new();
|
||||||
|
|
||||||
|
public int? ImplementerId { get; private set; }
|
||||||
|
|
||||||
|
public virtual Implementer? Implementer { get; set; } = new();
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
|
public static Order Create(JewelryStoreDatabase context, OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientId = model.ClientId,
|
||||||
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
||||||
|
JewelId = model.JewelId,
|
||||||
|
Jewel = context.Jewels.First(x => x.Id == model.JewelId),
|
||||||
|
ImplementerId = model.ImplementerId,
|
||||||
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(JewelryStoreDatabase context, OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
ImplementerId = model.ImplementerId;
|
||||||
|
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ClientId = ClientId,
|
||||||
|
ClientFIO = Client.ClientFIO,
|
||||||
|
JewelId = JewelId,
|
||||||
|
JewelName = Jewel.JewelName,
|
||||||
|
ImplementerId = ImplementerId,
|
||||||
|
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,13 @@ namespace JewelryStoreFileImplement
|
|||||||
private readonly string JewelFileName = "Jewel.xml";
|
private readonly string JewelFileName = "Jewel.xml";
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
private readonly string ShopFileName = "Shop.xml";
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
private readonly string ImplementerFileName = "Implementer.xml";
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Jewel> Jewels { get; private set; }
|
public List<Jewel> Jewels { get; private set; }
|
||||||
public List<Client> Clients { get; private set; }
|
public List<Client> Clients { get; private set; }
|
||||||
public List<Store> Shops { get; private set; }
|
public List<Store> Shops { get; private set; }
|
||||||
|
public List<Implementer> Implementers { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
@ -34,6 +36,7 @@ namespace JewelryStoreFileImplement
|
|||||||
|
|
||||||
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
||||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
|
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||||
|
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
@ -42,6 +45,7 @@ namespace JewelryStoreFileImplement
|
|||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
|
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
@ -13,96 +13,87 @@ namespace JewelryStoreFileImplement.Implements
|
|||||||
{
|
{
|
||||||
public class ImplementerStorage : IImplementerStorage
|
public class ImplementerStorage : IImplementerStorage
|
||||||
{
|
{
|
||||||
private readonly DataFileSingleton _source;
|
private readonly DataFileSingleton _source;
|
||||||
public ImplementerStorage()
|
public ImplementerStorage()
|
||||||
{
|
{
|
||||||
_source = DataFileSingleton.GetInstance();
|
_source = DataFileSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
|
||||||
{
|
|
||||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
|
|
||||||
if (res != null)
|
public List<ImplementerViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
_source.Implementers.Remove(res);
|
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||||
_source.SaveImplementers();
|
}
|
||||||
}
|
|
||||||
return res?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
{
|
{
|
||||||
if (model.Id.HasValue)
|
if (model == null)
|
||||||
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var res = GetElement(model);
|
||||||
|
return res != null ? new() { res } : new();
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null)
|
||||||
|
{
|
||||||
|
return _source.Implementers
|
||||||
|
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
if (model.ImplementerFIO != null && model.Password != null)
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
return _source.Implementers
|
{
|
||||||
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
|
if (model.Id.HasValue)
|
||||||
&& x.Password.Equals(model.Password))
|
{
|
||||||
?.GetViewModel;
|
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null && model.Password != null)
|
||||||
|
{
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel;
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null)
|
||||||
|
{
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (model.ImplementerFIO != null)
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
{
|
||||||
|
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||||
|
var res = Implementer.Create(model);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Add(res);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
}
|
{
|
||||||
|
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
res.Update(model);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
{
|
if (res != null)
|
||||||
return new();
|
{
|
||||||
}
|
_source.Implementers.Remove(res);
|
||||||
|
_source.SaveImplementers();
|
||||||
if (model.Id.HasValue)
|
}
|
||||||
{
|
return res?.GetViewModel;
|
||||||
var res = GetElement(model);
|
}
|
||||||
|
}
|
||||||
return res != null ? new() { res } : new();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (model.ImplementerFIO != null)
|
|
||||||
{
|
|
||||||
return _source.Implementers
|
|
||||||
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
|
||||||
|
|
||||||
var res = Implementer.Create(model);
|
|
||||||
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
_source.Implementers.Add(res);
|
|
||||||
_source.SaveImplementers();
|
|
||||||
}
|
|
||||||
|
|
||||||
return res?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
|
||||||
{
|
|
||||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
res.Update(model);
|
|
||||||
_source.SaveImplementers();
|
|
||||||
}
|
|
||||||
|
|
||||||
return res?.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,105 +14,122 @@ namespace JewelryStoreFileImplement.Implements
|
|||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
private readonly DataFileSingleton _source;
|
private readonly DataFileSingleton source;
|
||||||
public OrderStorage()
|
|
||||||
{
|
|
||||||
_source = DataFileSingleton.GetInstance();
|
|
||||||
}
|
|
||||||
public List<OrderViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
return _source.Orders.Select(x => SAddJewelName(x.GetViewModel)).ToList();
|
|
||||||
}
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (model.DateFrom.HasValue)
|
|
||||||
{
|
|
||||||
return _source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)).ToList();
|
|
||||||
}
|
|
||||||
if (model.ClientId.HasValue && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return _source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
if (model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
|
|
||||||
}
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (model.ImplementerId.HasValue && model.Statuses != null)
|
|
||||||
{
|
|
||||||
return _source.Orders .FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&model.Statuses.Contains(x.Status))?.GetViewModel;
|
|
||||||
}
|
|
||||||
if (model.ImplementerId.HasValue)
|
|
||||||
{
|
|
||||||
return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!model.Id.HasValue)
|
public OrderStorage()
|
||||||
{
|
{
|
||||||
return null;
|
source = DataFileSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
return SAddJewelName(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel);
|
|
||||||
}
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
|
|
||||||
var newOrder = Order.Create(model);
|
|
||||||
if (newOrder == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_source.Orders.Add(newOrder);
|
|
||||||
_source.SaveOrders();
|
|
||||||
return SAddJewelName(newOrder.GetViewModel);
|
|
||||||
}
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (order == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
order.Update(model);
|
|
||||||
_source.SaveOrders();
|
|
||||||
return SAddJewelName(order.GetViewModel);
|
|
||||||
}
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
_source.Orders.Remove(element);
|
|
||||||
_source.SaveOrders();
|
|
||||||
return SAddJewelName(element.GetViewModel);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel SAddJewelName(OrderViewModel fullModel)
|
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachJewelName(x.GetViewModel)).ToList();
|
||||||
{
|
|
||||||
string? jewelName = _source.Jewels.FirstOrDefault(x => x.Id == fullModel?.JewelId)?.JewelName;
|
|
||||||
if (jewelName != null) fullModel.JewelName = jewelName;
|
|
||||||
return fullModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OrderViewModel GetViewModel(Order order)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
var viewModel = order.GetViewModel;
|
if (model.DateFrom.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
|
.Select(x => GetViewModel(x)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.ClientId.HasValue && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!model.ImplementerId.HasValue && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.ImplementerId == model.ImplementerId).Select(x => x.GetViewModel).ToList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
|
||||||
|
}
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (model.ImplementerId.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
||||||
|
}
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return AttachJewelName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel GetViewModel(Order order)
|
||||||
|
{
|
||||||
|
var viewModel = order.GetViewModel;
|
||||||
|
|
||||||
|
var Jewel = source.Jewels.FirstOrDefault(x => x.Id == order.JewelId);
|
||||||
|
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
||||||
|
|
||||||
|
if (Jewel != null)
|
||||||
|
{
|
||||||
|
viewModel.JewelName = Jewel.JewelName;
|
||||||
|
}
|
||||||
|
if (client != null)
|
||||||
|
{
|
||||||
|
viewModel.ClientFIO = client.ClientFIO;
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Orders.Add(newOrder);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AttachJewelName(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AttachJewelName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order != null)
|
||||||
|
{
|
||||||
|
source.Orders.Remove(order);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AttachJewelName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel? AttachJewelName(OrderViewModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var Jewel = source.Jewels.FirstOrDefault(x => x.Id == model.JewelId);
|
||||||
|
if (Jewel != null)
|
||||||
|
{
|
||||||
|
model.JewelName = Jewel.JewelName;
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var jewel = _source.Jewels.FirstOrDefault(x => x.Id == order.JewelId);
|
|
||||||
var client = _source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
|
||||||
if (jewel != null)
|
|
||||||
{
|
|
||||||
viewModel.JewelName = jewel.JewelName;
|
|
||||||
}
|
|
||||||
if (client != null)
|
|
||||||
{
|
|
||||||
viewModel.ClientFIO = client.ClientFIO;
|
|
||||||
}
|
|
||||||
return viewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,16 @@ namespace JewelryStoreListImplement
|
|||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Jewel> Jewels { get; set; }
|
public List<Jewel> Jewels { get; set; }
|
||||||
public List<Store> Stores { get; set; }
|
public List<Store> Stores { get; set; }
|
||||||
|
public List<Implementer> Implementers { get; set; }
|
||||||
|
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Jewels = new List<Jewel>();
|
Jewels = new List<Jewel>();
|
||||||
Stores = new List<Store>();
|
Stores = new List<Store>();
|
||||||
}
|
Implementers = new List<Implementer>();
|
||||||
|
}
|
||||||
|
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
@ -13,119 +13,111 @@ namespace JewelryStoreListImplement.Implements
|
|||||||
{
|
{
|
||||||
public class ImplementerStorage : IImplementerStorage
|
public class ImplementerStorage : IImplementerStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public ImplementerStorage()
|
public ImplementerStorage()
|
||||||
{
|
{
|
||||||
_source = DataListSingleton.GetInstance();
|
_source = DataListSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _source.Implementers.Count; ++i)
|
for (int i = 0; i < _source.Implementers.Count; ++i)
|
||||||
{
|
{
|
||||||
if (_source.Implementers[i].Id == model.Id)
|
if (_source.Implementers[i].Id == model.Id)
|
||||||
{
|
{
|
||||||
var element = _source.Implementers[i];
|
var element = _source.Implementers[i];
|
||||||
_source.Implementers.RemoveAt(i);
|
_source.Implementers.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return element.GetViewModel;
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
}
|
{
|
||||||
}
|
foreach (var x in _source.Implementers)
|
||||||
return null;
|
{
|
||||||
}
|
if (model.Id.HasValue && x.Id == model.Id)
|
||||||
|
{
|
||||||
|
return x.GetViewModel;
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null && model.Password != null && x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))
|
||||||
|
{
|
||||||
|
return x.GetViewModel;
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
{
|
||||||
|
return x.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
{
|
{
|
||||||
foreach (var x in _source.Implementers)
|
if (model == null)
|
||||||
{
|
{
|
||||||
if (model.Id.HasValue && x.Id == model.Id)
|
return new();
|
||||||
return x.GetViewModel;
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var res = GetElement(model);
|
||||||
|
return res != null ? new() { res } : new();
|
||||||
|
}
|
||||||
|
|
||||||
if (model.ImplementerFIO != null && model.Password != null &&
|
List<ImplementerViewModel> result = new();
|
||||||
x.ImplementerFIO.Equals(model.ImplementerFIO) &&
|
if (model.ImplementerFIO != null)
|
||||||
x.Password.Equals(model.Password))
|
{
|
||||||
return x.GetViewModel;
|
foreach (var implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
{
|
||||||
|
result.Add(implementer.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
|
public List<ImplementerViewModel> GetFullList()
|
||||||
return x.GetViewModel;
|
{
|
||||||
}
|
var result = new List<ImplementerViewModel>();
|
||||||
return null;
|
foreach (var implementer in _source.Implementers)
|
||||||
}
|
{
|
||||||
|
result.Add(implementer.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
model.Id = 1;
|
||||||
{
|
foreach (var implementer in _source.Implementers)
|
||||||
return new();
|
{
|
||||||
}
|
if (model.Id <= implementer.Id)
|
||||||
|
{
|
||||||
|
model.Id = implementer.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var res = Implementer.Create(model);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Add(res);
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
if (model.Id.HasValue)
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
{
|
{
|
||||||
var res = GetElement(model);
|
foreach (var implementer in _source.Implementers)
|
||||||
|
{
|
||||||
return res != null ? new() { res } : new();
|
if (implementer.Id == model.Id)
|
||||||
}
|
{
|
||||||
|
implementer.Update(model);
|
||||||
List<ImplementerViewModel> result = new();
|
return implementer.GetViewModel;
|
||||||
|
}
|
||||||
if (model.ImplementerFIO != null)
|
}
|
||||||
{
|
return null;
|
||||||
foreach (var implementer in _source.Implementers)
|
}
|
||||||
{
|
}
|
||||||
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
|
|
||||||
{
|
|
||||||
result.Add(implementer.GetViewModel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ImplementerViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
var result = new List<ImplementerViewModel>();
|
|
||||||
|
|
||||||
foreach (var implementer in _source.Implementers)
|
|
||||||
{
|
|
||||||
result.Add(implementer.GetViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = 1;
|
|
||||||
|
|
||||||
foreach (var implementer in _source.Implementers)
|
|
||||||
{
|
|
||||||
if (model.Id <= implementer.Id)
|
|
||||||
{
|
|
||||||
model.Id = implementer.Id + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = Implementer.Create(model);
|
|
||||||
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
_source.Implementers.Add(res);
|
|
||||||
}
|
|
||||||
return res?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
|
||||||
{
|
|
||||||
foreach (var implementer in _source.Implementers)
|
|
||||||
{
|
|
||||||
if (implementer.Id == model.Id)
|
|
||||||
{
|
|
||||||
implementer.Update(model);
|
|
||||||
|
|
||||||
return implementer.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,174 +8,168 @@ namespace JewelryStoreListImplement.Implements
|
|||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
public OrderStorage()
|
public OrderStorage()
|
||||||
{
|
{
|
||||||
_source = DataListSingleton.GetInstance();
|
_source = DataListSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
var result = new List<OrderViewModel>();
|
||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
result.Add(AccessJewelStorage(order.GetViewModel));
|
result.Add(AttachJewelName(order.GetViewModel));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
var result = new List<OrderViewModel>();
|
||||||
if (model.DateFrom.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
{
|
{
|
||||||
return result;
|
foreach (var order in _source.Orders)
|
||||||
foreach (var order in _source.Orders)
|
{
|
||||||
{
|
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
{
|
||||||
{
|
result.Add(GetViewModel(order));
|
||||||
result.Add(GetViewModel(order));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (model.ClientId.HasValue && !model.Id.HasValue)
|
||||||
else if (model.ClientId.HasValue && !model.Id.HasValue)
|
{
|
||||||
{
|
foreach (var order in _source.Orders)
|
||||||
foreach (var order in _source.Orders)
|
{
|
||||||
{
|
if (order.ClientId == model.ClientId)
|
||||||
if (order.ClientId == model.ClientId)
|
{
|
||||||
{
|
result.Add(GetViewModel(order));
|
||||||
result.Add(GetViewModel(order));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (model.ImplementerId.HasValue && !model.Id.HasValue)
|
||||||
else if (model.Id.HasValue)
|
{
|
||||||
{
|
foreach (var order in _source.Orders)
|
||||||
foreach (var order in _source.Orders)
|
{
|
||||||
{
|
if (order.ImplementerId == model.ImplementerId)
|
||||||
if (order.Id == model.Id)
|
{
|
||||||
{
|
result.Add(GetViewModel(order));
|
||||||
result.Add(GetViewModel(order));
|
}
|
||||||
}
|
}
|
||||||
else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
|
}
|
||||||
{
|
else if (model.Id.HasValue)
|
||||||
result.Add(GetViewModel(order));
|
{
|
||||||
}
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
result.Add(GetViewModel(order));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
else if (model.Statuses != null && model.Statuses.Contains(order.Status))
|
private OrderViewModel GetViewModel(Order order)
|
||||||
{
|
{
|
||||||
result.Add(GetViewModel(order));
|
var viewModel = order.GetViewModel;
|
||||||
}
|
foreach (var package in _source.Jewels)
|
||||||
}
|
{
|
||||||
}
|
if (package.Id == order.JewelId)
|
||||||
return result;
|
{
|
||||||
}
|
viewModel.JewelName = package.JewelName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var client in _source.Clients)
|
||||||
|
{
|
||||||
|
if (client.Id == order.ClientId)
|
||||||
|
{
|
||||||
|
viewModel.ClientFIO = client.ClientFIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
if (model.Id.HasValue && order.Id == model.Id)
|
if (model.Id.HasValue && order.Id == model.Id)
|
||||||
{
|
{
|
||||||
return AccessJewelStorage(order.GetViewModel);
|
return AttachJewelName(order.GetViewModel);
|
||||||
}
|
}
|
||||||
else if (model.ImplementerId.HasValue && model.Statuses != null && order.ImplementerId == model.ImplementerId &&
|
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
|
||||||
model.Statuses.Contains(order.Status))
|
{
|
||||||
{
|
return GetViewModel(order);
|
||||||
return GetViewModel(order);
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return GetViewModel(order);
|
model.Id = 1;
|
||||||
}
|
foreach (var order in _source.Orders)
|
||||||
}
|
{
|
||||||
return null;
|
if (model.Id <= order.Id)
|
||||||
}
|
{
|
||||||
|
model.Id = order.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
return AttachJewelName(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
model.Id = 1;
|
foreach (var order in _source.Orders)
|
||||||
foreach (var order in _source.Orders)
|
{
|
||||||
{
|
if (order.Id == model.Id)
|
||||||
if (model.Id <= order.Id)
|
{
|
||||||
{
|
order.Update(model);
|
||||||
model.Id = order.Id + 1;
|
return AttachJewelName(order.GetViewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var newOrder = Order.Create(model);
|
return null;
|
||||||
if (newOrder == null)
|
}
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_source.Orders.Add(newOrder);
|
|
||||||
return AccessJewelStorage(newOrder.GetViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
foreach (var order in _source.Orders)
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||||
{
|
{
|
||||||
if (order.Id == model.Id)
|
if (_source.Orders[i].Id == model.Id)
|
||||||
{
|
{
|
||||||
order.Update(model);
|
var element = _source.Orders[i];
|
||||||
return AccessJewelStorage(order.GetViewModel);
|
_source.Orders.RemoveAt(i);
|
||||||
}
|
return AttachJewelName(element.GetViewModel);
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
private OrderViewModel AttachJewelName(OrderViewModel model)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
foreach (var Jewel in _source.Jewels)
|
||||||
{
|
{
|
||||||
if (_source.Orders[i].Id == model.Id)
|
if (Jewel.Id == model.JewelId)
|
||||||
{
|
{
|
||||||
var element = _source.Orders[i];
|
model.JewelName = Jewel.JewelName;
|
||||||
_source.Orders.RemoveAt(i);
|
return model;
|
||||||
return AccessJewelStorage(element.GetViewModel);
|
}
|
||||||
}
|
}
|
||||||
}
|
return model;
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public OrderViewModel AccessJewelStorage(OrderViewModel model)
|
|
||||||
{
|
|
||||||
foreach (var jewel in _source.Jewels)
|
|
||||||
{
|
|
||||||
if (jewel.Id == model.JewelId)
|
|
||||||
{
|
|
||||||
model.JewelName = jewel.JewelName;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OrderViewModel GetViewModel(Order order)
|
|
||||||
{
|
|
||||||
var viewModel = order.GetViewModel;
|
|
||||||
foreach (var jewel in _source.Jewels)
|
|
||||||
{
|
|
||||||
if (jewel.Id == order.JewelId)
|
|
||||||
{
|
|
||||||
viewModel.JewelName = jewel.JewelName;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (var client in _source.Clients)
|
|
||||||
{
|
|
||||||
if (client.Id == order.ClientId)
|
|
||||||
{
|
|
||||||
viewModel.ClientFIO = client.ClientFIO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return viewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -16,10 +16,13 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<IJewelStorage, JewelStorage>();
|
builder.Services.AddTransient<IJewelStorage, JewelStorage>();
|
||||||
builder.Services.AddTransient<IStoreStorage, StoreStorage>();
|
builder.Services.AddTransient<IStoreStorage, StoreStorage>();
|
||||||
|
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<IJewelLogic, JewelLogic>();
|
builder.Services.AddTransient<IJewelLogic, JewelLogic>();
|
||||||
builder.Services.AddTransient<IStoreLogic, StoreLogic>();
|
builder.Services.AddTransient<IStoreLogic, StoreLogic>();
|
||||||
|
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
Loading…
Reference in New Issue
Block a user