add listImplenets
This commit is contained in:
parent
a6bcc01785
commit
10a579904a
@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiB
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{A273021E-72E7-4C23-927C-A3E4851BD8D1}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{A273021E-72E7-4C23-927C-A3E4851BD8D1}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushibarListImplement", "SushibarListImplement\SushibarListImplement.csproj", "{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -33,6 +35,10 @@ Global
|
|||||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -4,6 +4,7 @@ using SushiBarContracts.BusinessLogicsContracts;
|
|||||||
using SushiBarContracts.SearchModels;
|
using SushiBarContracts.SearchModels;
|
||||||
using SushiBarContracts.StoragesContracts;
|
using SushiBarContracts.StoragesContracts;
|
||||||
using SushiBarContracts.ViewModels;
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Enums;
|
||||||
|
|
||||||
namespace SushiBarBusinessLogic.BusinessLogics
|
namespace SushiBarBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
@ -32,27 +33,18 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
return UpdateStatus(model, OrderStatus.Issued);
|
||||||
OrderViewModel? element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
|
||||||
if (element == null || model.Status - element?.Status != 1)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Delivery order is not ready");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
element.Status = SushiBarDataModels.Enums.OrderStatus.Ready;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FinishOrder(OrderBindingModel model)
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model, false);
|
||||||
OrderViewModel? element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
if (element == null || model.Status - element?.Status != 1)
|
if (_orderStorage.Delete(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Finish order is not ready");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
element.Status = SushiBarDataModels.Enums.OrderStatus.Issued;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,16 +63,29 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList .Id:{Id}", model?.Id);
|
return UpdateStatus(model, OrderStatus.Performed);
|
||||||
List<OrderViewModel> list = _orderStorage.GetFullList();
|
}
|
||||||
foreach (OrderViewModel order in list)
|
|
||||||
|
private bool UpdateStatus(OrderBindingModel model, OrderStatus status)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status + 1 != status)
|
||||||
{
|
{
|
||||||
if (order.Status is >= (SushiBarDataModels.Enums.OrderStatus)1 and not (SushiBarDataModels.Enums.OrderStatus)3)
|
_logger.LogWarning("Status update operation failed");
|
||||||
{
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
model.Status = status;
|
||||||
|
if (model.Status is OrderStatus.Issued)
|
||||||
|
{
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
}
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
model.Status--;
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
|
24
SushiBar/SushibarListImplement/DataListSingleton.cs
Normal file
24
SushiBar/SushibarListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using SushibarListImplement.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement
|
||||||
|
{
|
||||||
|
public class DataListSingleton
|
||||||
|
{
|
||||||
|
private static DataListSingleton? _instance;
|
||||||
|
public List<Component> Components { get; set; }
|
||||||
|
public List<Order> Orders { get; set; }
|
||||||
|
public List<Sushi> Sushi { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Components = new List<Component>();
|
||||||
|
Orders = new List<Order>();
|
||||||
|
Sushi = new List<Sushi>();
|
||||||
|
}
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
_instance ??= new DataListSingleton();
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
103
SushiBar/SushibarListImplement/Implements/ComponentStorage.cs
Normal file
103
SushiBar/SushibarListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushibarListImplement.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component? 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
106
SushiBar/SushibarListImplement/Implements/OrderStorage.cs
Normal file
106
SushiBar/SushibarListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushibarListImplement.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Sushi.Count; i++)
|
||||||
|
{
|
||||||
|
if (_source.Orders[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
Order order = _source.Orders[i];
|
||||||
|
_source.Orders.RemoveAt(i);
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (Order order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
List<OrderViewModel> list = new();
|
||||||
|
if (model.Id == 0)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
foreach (Order order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
list.Add(order.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
List<OrderViewModel> list = new();
|
||||||
|
foreach (Order order in _source.Orders)
|
||||||
|
{
|
||||||
|
list.Add(order.GetViewModel);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (Order order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id <= order.Id)
|
||||||
|
{
|
||||||
|
model.Id = order.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Order? newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
return newOrder.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (Order order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
order.Update(model);
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
102
SushiBar/SushibarListImplement/Implements/SushiStorage.cs
Normal file
102
SushiBar/SushibarListImplement/Implements/SushiStorage.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.SearchModels;
|
||||||
|
using SushiBarContracts.StoragesContracts;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushibarListImplement.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement.Implements
|
||||||
|
{
|
||||||
|
public class SushiStorage : ISushiStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public SushiStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<SushiViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<SushiViewModel>();
|
||||||
|
foreach (var sushi in _source.Sushi)
|
||||||
|
{
|
||||||
|
result.Add(sushi.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<SushiViewModel> GetFilteredList(SushiSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<SushiViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.SushiName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var sushi in _source.Sushi)
|
||||||
|
{
|
||||||
|
if (sushi.SushiName.Contains(model.SushiName))
|
||||||
|
{
|
||||||
|
result.Add(sushi.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public SushiViewModel? GetElement(SushiSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var sushi in _source.Sushi)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.SushiName) &&
|
||||||
|
sushi.SushiName == model.SushiName) ||
|
||||||
|
(model.Id.HasValue && sushi.Id == model.Id))
|
||||||
|
{
|
||||||
|
return sushi.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public SushiViewModel? Insert(SushiBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var sushi in _source.Sushi)
|
||||||
|
{
|
||||||
|
if (model.Id <= sushi.Id)
|
||||||
|
{
|
||||||
|
model.Id = sushi.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Sushi? newComponent = Sushi.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Sushi.Add(newComponent);
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public SushiViewModel? Update(SushiBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var sushi in _source.Sushi)
|
||||||
|
{
|
||||||
|
if (sushi.Id == model.Id)
|
||||||
|
{
|
||||||
|
sushi.Update(model);
|
||||||
|
return sushi.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public SushiViewModel? Delete(SushiBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Sushi.Count; i++)
|
||||||
|
{
|
||||||
|
if (_source.Sushi[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Sushi[i];
|
||||||
|
_source.Sushi.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
SushiBar/SushibarListImplement/Models/Component.cs
Normal file
44
SushiBar/SushibarListImplement/Models/Component.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public double Cost { get; set; }
|
||||||
|
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public static Component? Create(ComponentBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComponentBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComponentName = model.ComponentName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
public ComponentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComponentName = ComponentName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
62
SushiBar/SushibarListImplement/Models/Order.cs
Normal file
62
SushiBar/SushibarListImplement/Models/Order.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Enums;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int SushiId { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
|
||||||
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
|
public DateTime? DateImplement { get; set; } = null;
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SushiId = model.SushiId,
|
||||||
|
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;
|
||||||
|
SushiId = model.SushiId;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SushiId = SushiId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
49
SushiBar/SushibarListImplement/Models/Sushi.cs
Normal file
49
SushiBar/SushibarListImplement/Models/Sushi.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
|
using SushiBarDataModels.Models;
|
||||||
|
|
||||||
|
namespace SushibarListImplement.Models
|
||||||
|
{
|
||||||
|
public class Sushi : ISushiModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string SushiName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> SushiComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
public static Sushi? Create(SushiBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Sushi()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SushiName = model.SushiName,
|
||||||
|
Price = model.Price,
|
||||||
|
SushiComponents = model.SushiComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(SushiBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SushiName = model.SushiName;
|
||||||
|
Price = model.Price;
|
||||||
|
SushiComponents = model.SushiComponents;
|
||||||
|
}
|
||||||
|
public SushiViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SushiName = SushiName,
|
||||||
|
Price = Price,
|
||||||
|
SushiComponents = SushiComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
14
SushiBar/SushibarListImplement/SushibarListImplement.csproj
Normal file
14
SushiBar/SushibarListImplement/SushibarListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\SushiBarModels\SushiBarDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user