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)
{
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 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)
{
@ -37,6 +37,9 @@ namespace FishFactoryFileImplement.Implements
{
return null;
}
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)
@ -78,6 +81,7 @@ namespace FishFactoryFileImplement.Implements
var viewModel = order.GetViewModel;
var canned = source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
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;
@ -86,6 +90,10 @@ namespace FishFactoryFileImplement.Implements
{
viewModel.ClientFIO = client.ClientFIO;
}
if (implementer != null)
{
viewModel.ImplementerFIO = implementer.ImplementerFIO;
}
return viewModel;
}
}

View File

@ -20,45 +20,17 @@ namespace FishFactoryListImplement.Implements
}
public List<OrderViewModel> GetFullList()
{
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(GetViewModel(order));
}
return result;
return _source.Orders.Select(x => GetViewModel(x)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel
model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue)
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null)
{
return result;
return new();
}
if (model.ClientId.HasValue)
{
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;
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)
{
@ -66,14 +38,9 @@ namespace FishFactoryListImplement.Implements
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && order.Id == model.Id)
{
return order.GetViewModel;
}
}
return null;
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)
{
@ -122,23 +89,25 @@ namespace FishFactoryListImplement.Implements
{
var viewModel = order.GetViewModel;
foreach (var canned in _source.Canneds)
{
if (canned.Id == order.CannedId)
var canned = _source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
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;
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
if (client != null)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
if (implementer != null)
{
viewModel.ImplementerFIO = implementer.ImplementerFIO;
}
return viewModel;