''''''''''''''
This commit is contained in:
parent
318326ae54
commit
c0cd5e4da8
@ -11,7 +11,7 @@ namespace FlowerShopContracts.BindingModels
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int FlowerId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -13,9 +13,9 @@ namespace FlowerShopContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int FlowerId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public string FlowerName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
|
@ -9,7 +9,7 @@ namespace FlowerShopDataModels
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int ProductId { get; }
|
||||
int FlowerId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
105
FlowerShopListImplement/ComponentStorage.cs
Normal file
105
FlowerShopListImplement/ComponentStorage.cs
Normal file
@ -0,0 +1,105 @@
|
||||
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 ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
var result = new List<ComponentViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (component.ComponentName.Contains(model.ComponentName))
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || (model.Id.HasValue && component.Id == model.Id))
|
||||
{
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (model.Id <= component.Id)
|
||||
{
|
||||
model.Id = component.Id + 1;
|
||||
}
|
||||
}
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Components.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
foreach (var component in _source.Components)
|
||||
{
|
||||
if (component.Id == model.Id)
|
||||
{
|
||||
component.Update(model);
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Components.Count; ++i)
|
||||
{
|
||||
if (_source.Components[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Components[i];
|
||||
_source.Components.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
31
FlowerShopListImplement/DataListSingleton.cs
Normal file
31
FlowerShopListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using FlowerShopListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Flower> Flowers { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Flowers = new List<Flower>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
105
FlowerShopListImplement/FlowerStorage.cs
Normal file
105
FlowerShopListImplement/FlowerStorage.cs
Normal file
@ -0,0 +1,105 @@
|
||||
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
|
||||
{
|
||||
public class FlowerStorage : IFlowerStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public FlowerStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<FlowerViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<FlowerViewModel>();
|
||||
foreach (var flower in _source.Flowers)
|
||||
{
|
||||
result.Add(flower.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<FlowerViewModel> GetFilteredList(FlowerSearchModel model)
|
||||
{
|
||||
var result = new List<FlowerViewModel>();
|
||||
if (string.IsNullOrEmpty(model.FlowerName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var flower in _source.Flowers)
|
||||
{
|
||||
if (flower.FlowerName.Contains(model.FlowerName))
|
||||
{
|
||||
result.Add(flower.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public FlowerViewModel? GetElement(FlowerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.FlowerName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var flower in _source.Flowers)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.FlowerName) && flower.FlowerName == model.FlowerName) || (model.Id.HasValue && flower.Id == model.Id))
|
||||
{
|
||||
return flower.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public FlowerViewModel? Insert(FlowerBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var flower in _source.Flowers)
|
||||
{
|
||||
if (model.Id <= flower.Id)
|
||||
{
|
||||
model.Id = flower.Id + 1;
|
||||
}
|
||||
}
|
||||
var newFlower = Flower.Create(model);
|
||||
if (newFlower == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Flowers.Add(newFlower);
|
||||
return newFlower.GetViewModel;
|
||||
}
|
||||
public FlowerViewModel? Update(FlowerBindingModel model)
|
||||
{
|
||||
foreach (var flower in _source.Flowers)
|
||||
{
|
||||
if (flower.Id == model.Id)
|
||||
{
|
||||
flower.Update(model);
|
||||
return flower.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public FlowerViewModel? Delete(FlowerBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Flowers.Count; ++i)
|
||||
{
|
||||
if (_source.Flowers[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Flowers[i];
|
||||
_source.Flowers.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
66
FlowerShopListImplement/Order.cs
Normal file
66
FlowerShopListImplement/Order.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Enums;
|
||||
using FlowerShopDataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopListImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int FlowerId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; }
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
FlowerId = model.FlowerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Id = model.Id;
|
||||
FlowerId = model.FlowerId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FlowerId = FlowerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
119
FlowerShopListImplement/OrderStorage.cs
Normal file
119
FlowerShopListImplement/OrderStorage.cs
Normal file
@ -0,0 +1,119 @@
|
||||
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)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user