почти готовая лаба 2, только есть баг - заказы не сразу отображаются
This commit is contained in:
parent
a4ac8cb1ad
commit
8b29b0dcc9
@ -1,10 +1,11 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
using SushiBarBusinessLogic.BusinessLogic;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarListImplement.Implements;
|
||||
using SushiBarFileImplement.Implements;
|
||||
using SushiBarView;
|
||||
|
||||
namespace SushiBar
|
||||
@ -28,7 +29,6 @@ namespace SushiBar
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
//Application.Run(new Form1());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
@ -41,9 +41,11 @@ namespace SushiBar
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ISushiStorage, SushiStorage>();
|
||||
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ISushiLogic, SushiLogic>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
|
@ -34,6 +34,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
|
||||
<ProjectReference Include="..\SushiBarListImplement\SushiBarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace SushiBarFileImplement
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!;
|
||||
Orders = new List<Order>();
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
}
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
|
72
SushiBarFileImplement/Implements/ComponentStorage.cs
Normal file
72
SushiBarFileImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.SearchModel;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarFileImplement.Models;
|
||||
|
||||
namespace SushiBarFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) &&
|
||||
x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Components.Remove(element);
|
||||
source.SaveComponents();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
83
SushiBarFileImplement/Implements/OrderStorage.cs
Normal file
83
SushiBarFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.SearchModel;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarFileImplement.Models;
|
||||
|
||||
namespace SushiBarFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(element);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
var sushi = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId);
|
||||
if(sushi != null)
|
||||
{
|
||||
viewModel.SushiName = sushi.SushiName;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
}
|
77
SushiBarFileImplement/Implements/SushiStorage.cs
Normal file
77
SushiBarFileImplement/Implements/SushiStorage.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.SearchModel;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarFileImplement.Models;
|
||||
|
||||
|
||||
namespace SushiBarFileImplement.Implements
|
||||
{
|
||||
public class SushiStorage : ISushiStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public SushiStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<SushiViewModel> GetFullList()
|
||||
{
|
||||
return source.Sushis.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<SushiViewModel> GetFilteredList(SushiSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SushiName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Sushis.Where(x => x.SushiName.Contains(model.SushiName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public SushiViewModel? GetElement(SushiSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Sushis.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SushiName) &&
|
||||
x.SushiName == model.SushiName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public SushiViewModel? Insert(SushiBindingModel model)
|
||||
{
|
||||
model.Id = source.Sushis.Count > 0 ? source.Sushis.Max(x => x.Id) + 1 : 1;
|
||||
var newSushi = Sushi.Create(model);
|
||||
if (newSushi == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Sushis.Add(newSushi);
|
||||
source.SaveSushis();
|
||||
return newSushi.GetViewModel;
|
||||
}
|
||||
public SushiViewModel? Update(SushiBindingModel model)
|
||||
{
|
||||
var sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (sushi == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
sushi.Update(model);
|
||||
source.SaveSushis();
|
||||
return sushi.GetViewModel;
|
||||
}
|
||||
public SushiViewModel? Delete(SushiBindingModel model)
|
||||
{
|
||||
var element = source.Sushis.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Sushis.Remove(element);
|
||||
source.SaveSushis();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,11 +11,11 @@ namespace SushiBarFileImplement.Models
|
||||
public int Id { get; private set; }
|
||||
public int SushiId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
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)
|
||||
{
|
||||
@ -28,7 +28,8 @@ namespace SushiBarFileImplement.Models
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
public static Order? Create(XElement element)
|
||||
@ -43,7 +44,7 @@ namespace SushiBarFileImplement.Models
|
||||
SushiId = Convert.ToInt32(element.Element("SushiId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus),element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null :
|
||||
Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||
@ -62,6 +63,7 @@ namespace SushiBarFileImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
|
@ -20,8 +20,10 @@ namespace SushiBarFileImplement.Models
|
||||
if (_sushiComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_sushiComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key)
|
||||
as IComponentModel)!, y.Value));
|
||||
_sushiComponents = Components.ToDictionary(x => x.Key, y =>
|
||||
((source.Components.FirstOrDefault(z => z.Id == y.Key)
|
||||
as IComponentModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _sushiComponents;
|
||||
}
|
||||
|
@ -12,8 +12,4 @@
|
||||
<ProjectReference Include="..\SushiBarListImplement\SushiBarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -42,11 +42,7 @@ namespace SushiBarListImplement.Models
|
||||
{
|
||||
return;
|
||||
}
|
||||
SushiId = model.SushiId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user