ПИбд-23 Салин Олег Алексеевич Лабораторная работа №6 #19
@ -22,7 +22,7 @@ namespace IceCreamShopFileImplement.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders
|
||||
.Select(x => AccessIceCreamStorage(x.GetViewModel))
|
||||
.Select(x => AccessStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -30,15 +30,17 @@ namespace IceCreamShopFileImplement.Implements
|
||||
model)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => (
|
||||
(!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
|
||||
&&
|
||||
(!model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
)
|
||||
)
|
||||
.Select(x => AccessIceCreamStorage(x.GetViewModel))
|
||||
.Where(x => (
|
||||
(!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
|
||||
&&
|
||||
(!model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
&&
|
||||
(!model.Status.HasValue || x.Status == model.Status)
|
||||
)
|
||||
)
|
||||
.Select(x => AccessStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -48,8 +50,11 @@ model)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return AccessIceCreamStorage(source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel);
|
||||
return AccessStorage(source.Orders
|
||||
.FirstOrDefault(
|
||||
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(model.ImplementerId.HasValue && model.Status.HasValue &&
|
||||
x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
@ -62,7 +67,7 @@ model)
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return AccessIceCreamStorage(newOrder.GetViewModel);
|
||||
return AccessStorage(newOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -74,7 +79,7 @@ model)
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return AccessIceCreamStorage(order.GetViewModel);
|
||||
return AccessStorage(order.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
@ -84,34 +89,25 @@ model)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
return AccessIceCreamStorage(element.GetViewModel);
|
||||
return AccessStorage(element.GetViewModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel AccessIceCreamStorage(OrderViewModel model)
|
||||
public OrderViewModel AccessStorage(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
foreach (var iceCream in source.IceCreams)
|
||||
{
|
||||
if (iceCream.Id == model.IceCreamId)
|
||||
{
|
||||
model.IceCreamName = iceCream.IceCreamName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public OrderViewModel AccessClientStorage(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client != null)
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
return model;
|
||||
var iceCream = source.IceCreams.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 (iceCream != null)
|
||||
model.IceCreamName = iceCream.IceCreamName;
|
||||
if (client != null)
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
if (implementer != null)
|
||||
model.ImplementerFIO = implementer.ImplementerFIO;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace IceCreamShopListImplement.Implements
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(AccessIceCreamStorage(order.GetViewModel));
|
||||
result.Add(AccessStorage(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -34,11 +34,14 @@ namespace IceCreamShopListImplement.Implements
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if ((!model.Id.HasValue || order.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || order.DateCreate <= model.DateTo) &&
|
||||
(!model.ClientId.HasValue || order.ClientId == model.ClientId)) ;
|
||||
(!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || order.DateCreate <= model.DateTo)
|
||||
&&
|
||||
(!model.ClientId.HasValue || order.ClientId == model.ClientId)
|
||||
&&
|
||||
(!model.Status.HasValue || order.Status == model.Status)) ;
|
||||
{
|
||||
result.Add(AccessIceCreamStorage(order.GetViewModel));
|
||||
result.Add(AccessStorage(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -51,9 +54,11 @@ namespace IceCreamShopListImplement.Implements
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
if ((model.Id.HasValue && order.Id == model.Id) ||
|
||||
(model.ImplementerId.HasValue && model.Status.HasValue &&
|
||||
order.ImplementerId == model.ImplementerId && order.Status == model.Status))
|
||||
{
|
||||
return order.GetViewModel;
|
||||
return AccessStorage(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -102,28 +107,23 @@ namespace IceCreamShopListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel AccessIceCreamStorage(OrderViewModel model)
|
||||
{
|
||||
foreach (var iceCream in _source.IceCreams)
|
||||
{
|
||||
if (iceCream.Id == model.IceCreamId)
|
||||
{
|
||||
model.IceCreamName = iceCream.IceCreamName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public OrderViewModel AccessClientStorage(OrderViewModel model)
|
||||
{
|
||||
var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId);
|
||||
if (client != null)
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
return model;
|
||||
}
|
||||
public OrderViewModel AccessStorage(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
var iceCream = _source.IceCreams.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 (iceCream != null)
|
||||
model.IceCreamName = iceCream.IceCreamName;
|
||||
if (client != null)
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
if (implementer != null)
|
||||
model.ImplementerFIO = implementer.ImplementerFIO;
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user