2023-02-03 23:25:31 +04:00
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.SearchModels;
|
|
|
|
|
using ConfectioneryContracts.StoragesContract;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using ConfectioneryListImplement.Models;
|
2023-03-13 16:43:23 +04:00
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2023-02-03 23:25:31 +04:00
|
|
|
|
|
|
|
|
|
namespace ConfectioneryListImplement
|
|
|
|
|
{
|
|
|
|
|
public class OrderStorage : IOrderStorage
|
|
|
|
|
{
|
|
|
|
|
private readonly DataListSingleton _source;
|
|
|
|
|
public OrderStorage()
|
|
|
|
|
{
|
|
|
|
|
_source = DataListSingleton.GetInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel? Delete(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (_source.Orders[i].Id == model.Id)
|
|
|
|
|
{
|
|
|
|
|
var element = _source.Orders[i];
|
|
|
|
|
_source.Orders.RemoveAt(i);
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
|
|
|
|
if (model.Id.HasValue && order.Id == model.Id)
|
|
|
|
|
{
|
2023-02-05 22:03:41 +04:00
|
|
|
|
return GetViewModel(order);
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
2023-03-13 17:17:36 +04:00
|
|
|
|
else if (model.ImplementerId.HasValue && model.Statusses != null &&
|
|
|
|
|
order.ImplementerId == model.ImplementerId && model.Statusses.Contains(order.Status))
|
|
|
|
|
{
|
|
|
|
|
return GetViewModel(order);
|
|
|
|
|
}
|
|
|
|
|
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
|
|
|
|
|
{
|
|
|
|
|
return GetViewModel(order);
|
|
|
|
|
}
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<OrderViewModel>();
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
|
|
|
|
if (order.Id == model.Id)
|
|
|
|
|
{
|
2023-02-05 22:03:41 +04:00
|
|
|
|
return new() { GetViewModel(order) };
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
2023-03-13 16:43:23 +04:00
|
|
|
|
// если не ищем по айдишнику, значит ищем по диапазону дат
|
|
|
|
|
else if (model.DateFrom.HasValue && model.DateTo.HasValue &&
|
|
|
|
|
model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo)
|
|
|
|
|
{
|
|
|
|
|
result.Add(GetViewModel(order));
|
|
|
|
|
}
|
|
|
|
|
else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
|
|
|
|
|
{
|
|
|
|
|
result.Add(GetViewModel(order));
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
2023-03-13 17:17:36 +04:00
|
|
|
|
else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
|
|
|
|
|
{
|
|
|
|
|
result.Add(GetViewModel(order));
|
|
|
|
|
}
|
|
|
|
|
else if (model.Statusses != null && model.Statusses.Contains(order.Status))
|
|
|
|
|
{
|
|
|
|
|
result.Add(GetViewModel(order));
|
|
|
|
|
}
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
2023-03-13 16:43:23 +04:00
|
|
|
|
return result;
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<OrderViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
var result = new List<OrderViewModel>();
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
2023-02-05 22:03:41 +04:00
|
|
|
|
result.Add(GetViewModel(order));
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel? Insert(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
model.Id = 1;
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
|
|
|
|
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 newOrder.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel? Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
|
|
|
|
if (order.Id == model.Id)
|
|
|
|
|
{
|
|
|
|
|
order.Update(model);
|
|
|
|
|
return order.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-02-05 22:03:41 +04:00
|
|
|
|
|
|
|
|
|
private OrderViewModel GetViewModel(Order model)
|
|
|
|
|
{
|
|
|
|
|
var res = model.GetViewModel;
|
|
|
|
|
foreach (var pastry in _source.Pastry)
|
|
|
|
|
{
|
|
|
|
|
if (pastry.Id == model.PastryId)
|
|
|
|
|
{
|
|
|
|
|
res.PastryName = pastry.PastryName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2023-02-03 23:25:31 +04:00
|
|
|
|
}
|
|
|
|
|
}
|