2024-02-08 17:08:13 +04:00
|
|
|
|
using FlowerShopContracts.BindingModels;
|
|
|
|
|
using FlowerShopContracts.SearchModels;
|
|
|
|
|
using FlowerShopContracts.StoragesContracts;
|
|
|
|
|
using FlowerShopContracts.ViewModels;
|
|
|
|
|
using FlowerShopListImplement.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FlowerShopListImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class OrderStorage : IOrderStorage
|
|
|
|
|
{
|
|
|
|
|
private readonly DataListSingleton _source;
|
|
|
|
|
public OrderStorage()
|
|
|
|
|
{
|
|
|
|
|
_source = DataListSingleton.GetInstance();
|
|
|
|
|
}
|
|
|
|
|
public List<OrderViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
var result = new List<OrderViewModel>();
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
|
|
|
|
result.Add(AccessFlowerStorage(order.GetViewModel));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel
|
|
|
|
|
model)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<OrderViewModel>();
|
|
|
|
|
if (!model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
foreach (var order in _source.Orders)
|
|
|
|
|
{
|
2024-04-06 18:45:56 +04:00
|
|
|
|
if ((!model.Id.HasValue || order.Id == model.Id) &&
|
|
|
|
|
(!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) &&
|
|
|
|
|
(!model.DateTo.HasValue || order.DateCreate <= model.DateTo) &&
|
|
|
|
|
(!model.ClientId.HasValue || order.ClientId == model.ClientId))
|
2024-02-08 17:08:13 +04:00
|
|
|
|
{
|
|
|
|
|
result.Add(AccessFlowerStorage(order.GetViewModel));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return order.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
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 AccessFlowerStorage(OrderViewModel model)
|
|
|
|
|
{
|
|
|
|
|
foreach (var iceCream in _source.Flowers)
|
|
|
|
|
{
|
|
|
|
|
if (iceCream.Id == model.FlowerId)
|
|
|
|
|
{
|
|
|
|
|
model.FlowerName = iceCream.FlowerName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return model;
|
|
|
|
|
}
|
2024-04-06 18:45:56 +04:00
|
|
|
|
public OrderViewModel AccessClientStorage(OrderViewModel model)
|
|
|
|
|
{
|
|
|
|
|
var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId);
|
|
|
|
|
if (client != null)
|
|
|
|
|
model.ClientFIO = client.ClientFIO;
|
|
|
|
|
return model;
|
|
|
|
|
}
|
2024-02-08 17:08:13 +04:00
|
|
|
|
}
|
|
|
|
|
}
|