lab6fixick

This commit is contained in:
Дмитрий Блохин 2024-05-15 23:29:01 +04:00
parent 7061ab9992
commit b62cd91aa0
2 changed files with 36 additions and 59 deletions

View File

@ -24,12 +24,12 @@ namespace FishFactoryFileImplement.Implements
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null)
{ {
return new(); return new();
} }
return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList(); return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId || model.Status.Equals(x.Status)).Select(x => GetViewModel(x)).ToList();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
@ -37,8 +37,11 @@ namespace FishFactoryFileImplement.Implements
{ {
return null; return null;
} }
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; if (model.ImplementerId.HasValue && model.Status != null)
} return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Status.Equals(x.Status))?.GetViewModel;
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
@ -78,6 +81,7 @@ namespace FishFactoryFileImplement.Implements
var viewModel = order.GetViewModel; var viewModel = order.GetViewModel;
var canned = source.Canneds.FirstOrDefault(x => x.Id == order.CannedId); var canned = source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
var implementer = source.Implementers.FirstOrDefault(x => x.Id == order.ImplementerId);
if (canned != null) if (canned != null)
{ {
viewModel.CannedName = canned.CannedName; viewModel.CannedName = canned.CannedName;
@ -86,6 +90,10 @@ namespace FishFactoryFileImplement.Implements
{ {
viewModel.ClientFIO = client.ClientFIO; viewModel.ClientFIO = client.ClientFIO;
} }
if (implementer != null)
{
viewModel.ImplementerFIO = implementer.ImplementerFIO;
}
return viewModel; return viewModel;
} }
} }

View File

@ -20,45 +20,17 @@ namespace FishFactoryListImplement.Implements
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
var result = new List<OrderViewModel>(); return _source.Orders.Select(x => GetViewModel(x)).ToList();
foreach (var order in _source.Orders) }
{
result.Add(GetViewModel(order));
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel public List<OrderViewModel> GetFilteredList(OrderSearchModel
model) model)
{ {
var result = new List<OrderViewModel>(); if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null)
if (!model.Id.HasValue)
{ {
return result; return new();
} }
if (model.ClientId.HasValue) return _source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId || model.Status.Equals(x.Status)).Select(x => GetViewModel(x)).ToList();
{
foreach (var order in _source.Orders)
{
if (order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
}
}
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)
{
result.Add(GetViewModel(order));
}
}
}
return result;
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
@ -66,15 +38,10 @@ namespace FishFactoryListImplement.Implements
{ {
return null; return null;
} }
foreach (var order in _source.Orders) if (model.ImplementerId.HasValue && model.Status != null)
{ return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Status.Equals(x.Status))?.GetViewModel;
if (model.Id.HasValue && order.Id == model.Id) return _source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
{ }
return order.GetViewModel;
}
}
return null;
}
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
model.Id = 1; model.Id = 1;
@ -122,23 +89,25 @@ namespace FishFactoryListImplement.Implements
{ {
var viewModel = order.GetViewModel; var viewModel = order.GetViewModel;
foreach (var canned in _source.Canneds) var canned = _source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
{
if (canned.Id == order.CannedId)
{
viewModel.CannedName = canned.CannedName;
break; var client = _source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
}
var implementer = _source.Implementers.FirstOrDefault(x => x.Id == order.ImplementerId);
if (canned != null)
{
viewModel.CannedName = canned.CannedName;
} }
foreach (var client in _source.Clients) if (client != null)
{ {
if (client.Id == order.ClientId) viewModel.ClientFIO = client.ClientFIO;
{ }
viewModel.ClientFIO = client.ClientFIO;
break; if (implementer != null)
} {
viewModel.ImplementerFIO = implementer.ImplementerFIO;
} }
return viewModel; return viewModel;