изменил заказ

This commit is contained in:
bekodeg 2024-05-21 21:07:18 +04:00
parent 34f6602a59
commit f203356284

View File

@ -16,7 +16,7 @@ namespace SushiBarFileImplement.Implements
public List<OrderViewModel> GetFullList()
{
return source.Orders
.Select(x => AccessClientStorage(AccessSushiStorage(x.GetViewModel))!)
.Select(x => AccessStorage(x.GetViewModel))!
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -27,7 +27,7 @@ namespace SushiBarFileImplement.Implements
(!model.DateFrom.HasValue || o.DateCreate >= model.DateFrom) &&
(!model.DateTo.HasValue || o.DateCreate <= model.DateTo) &&
(!model.ClientId.HasValue || o.ClientId == model.ClientId))
.Select(o => AccessClientStorage(AccessSushiStorage(o.GetViewModel))!)
.Select(o => AccessStorage(o.GetViewModel)!)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
@ -36,9 +36,8 @@ namespace SushiBarFileImplement.Implements
{
return null;
}
return AccessClientStorage(AccessSushiStorage(
source.Orders
.FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel));
return AccessStorage(source.Orders
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel!);
}
public OrderViewModel? Insert(OrderBindingModel model)
{
@ -50,7 +49,7 @@ namespace SushiBarFileImplement.Implements
}
source.Orders.Add(newOrder);
source.SaveOrders();
return AccessClientStorage(AccessSushiStorage(newOrder.GetViewModel));
return AccessStorage(newOrder.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel model)
{
@ -61,7 +60,7 @@ namespace SushiBarFileImplement.Implements
}
element.Update(model);
source.SaveOrders();
return AccessClientStorage(AccessSushiStorage(element.GetViewModel));
return AccessStorage(element.GetViewModel);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
@ -70,32 +69,23 @@ namespace SushiBarFileImplement.Implements
{
source.Orders.Remove(element);
source.SaveOrders();
return AccessClientStorage(AccessSushiStorage(element.GetViewModel));
return AccessStorage(element.GetViewModel);
}
return null;
}
public OrderViewModel? AccessSushiStorage(OrderViewModel? model)
{
if (model == null)
return null;
foreach (var iceCream in source.Sushis)
{
if (iceCream.Id == model.SushiId)
{
model.SushiName = iceCream.SushiName;
break;
}
}
return model;
}
public OrderViewModel? AccessClientStorage(OrderViewModel? model)
public OrderViewModel AccessStorage(OrderViewModel model)
{
if (model == null)
return null;
var sushi = source.Sushis.FirstOrDefault(x => x.Id == model.Id);
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId);
if (sushi != null)
model.SushiName = sushi.SushiName;
if (client != null)
model.ClientFIO = client.ClientFIO;
if (implementer != null)
model.ImplementerName = implementer.ImplementerFIO;
return model;
}
}