Kharlamov A.A. Lab Work 01 #1
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AbstractFoodOrdersContracts\AbstractFoodOrdersContracts.csproj" />
|
||||
<ProjectReference Include="..\AbstractFoodOrdersDataModels\AbstractFoodOrdersDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,31 @@
|
||||
using AbstractFoodOrdersListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Dish> Products { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Products = new List<Product>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.Implements
|
||||
{
|
||||
internal class ComponentStorage
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.SearchModels;
|
||||
using AbstractFoodOrdersContracts.StoragesContracts;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.Implements
|
||||
{
|
||||
public class DishStorage : IDishStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public DishStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<DishViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<DishViewModel>();
|
||||
foreach (var dish in _source.Dishes)
|
||||
{
|
||||
result.Add(dish.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<DishViewModel> GetFilteredList(DishSearchModel model)
|
||||
{
|
||||
var result = new List<DishViewModel>();
|
||||
if (string.IsNullOrEmpty(model.DishName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var dish in _source.Dishes)
|
||||
{
|
||||
if (dish.DishName.Contains(model.DishName))
|
||||
{
|
||||
result.Add(dish.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public DishViewModel? GetElement(DishSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DishName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var dish in _source.Dishes)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.DishName) && dish.DishName == model.DishName) ||
|
||||
(model.Id.HasValue && dish.Id == model.Id))
|
||||
{
|
||||
return dish.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public DishViewModel? Insert(DishBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var dish in _source.Dishes)
|
||||
{
|
||||
if (model.Id <= dish.Id)
|
||||
{
|
||||
model.Id = dish.Id + 1;
|
||||
}
|
||||
}
|
||||
var newDish = Dish.Create(model);
|
||||
if (newDish == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Dishes.Add(newDish);
|
||||
return newDish.GetViewModel;
|
||||
}
|
||||
public DishViewModel? Update(DishBindingModel model)
|
||||
{
|
||||
foreach (var dish in _source.Dishes)
|
||||
{
|
||||
if (dish.Id == model.Id)
|
||||
{
|
||||
dish.Update(model);
|
||||
return dish.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public DishViewModel? Delete(DishBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Dishes.Count; ++i)
|
||||
{
|
||||
if (_source.Dishes[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Dishes[i];
|
||||
_source.Dishes.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.SearchModels;
|
||||
using AbstractFoodOrdersContracts.StoragesContracts;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.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(AttachReinforcedName(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
//А, собственно, этт метод не имеет ценности, так как повторяет функционал следующего
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model == null || !model.Id.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachReinforcedName(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 AttachReinforcedName(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 AttachReinforcedName(newOrder.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return AttachReinforcedName(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 AttachReinforcedName(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private OrderViewModel AttachReinforcedName(OrderViewModel model)
|
||||
{
|
||||
//Из всех мест, это выглядит наиболее подходящим, для данной манипуляции.
|
||||
//При расположении ниже нарушится целостность данных
|
||||
//При расположении выше будет нарушен принцип разделения уровней
|
||||
foreach (var reinforced in _source.Dishes)
|
||||
{
|
||||
if (reinforced.Id == model.DishId)
|
||||
{
|
||||
model.DishName = reinforced.DishName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
public double Cost { get; 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
|
||||
};
|
||||
}
|
||||
|
||||
}
|
49
FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs
Normal file
49
FoodOrders/AbstractFoodOrdersListImplement/Models/Dish.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.Models
|
||||
{
|
||||
public class Dish : IDishModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string DishName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
public static Dish? Create(ProductBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Dish(){ Id = model.Id, DishName = model.DishName, Price = model.Price, DishComponents = model.DishComponents };
|
||||
}
|
||||
public void Update(ProductBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DishName = model.DishName;
|
||||
Price = model.Price;
|
||||
DishComponents = model.DishComponents;
|
||||
}
|
||||
public DishViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DishName = DishName,
|
||||
Price = Price,
|
||||
DishComponents = DishComponents
|
||||
};
|
||||
}
|
||||
|
||||
}
|
63
FoodOrders/AbstractFoodOrdersListImplement/Models/Order.cs
Normal file
63
FoodOrders/AbstractFoodOrdersListImplement/Models/Order.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersDataModels.Enums;
|
||||
using AbstractFoodOrdersDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int DishId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
DishId = model.DishId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DishId = model.DishId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DishId = DishId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Не требуется обновлять все данные, только статус и дату выполнения