быть счастливой не получилось

This commit is contained in:
kamilia 2024-05-19 13:59:53 +04:00
parent c646b88323
commit 74755b7b5d
3 changed files with 80 additions and 11 deletions

View File

@ -66,7 +66,7 @@ namespace AircraftPlantListImplement.Implements
return result; return result;
} }
if (model.ClientId.HasValue && !model.Id.HasValue) else if(model.ClientId.HasValue && !model.Id.HasValue)
{ {
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
@ -74,6 +74,27 @@ namespace AircraftPlantListImplement.Implements
} }
} }
else if (model.ImplementerId.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ImplementerId == model.ImplementerId)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Status != null)
{
foreach (var order in _source.Orders)
{
if (order.Status.Equals(model.Status))
{
result.Add(GetViewModel(order));
}
}
}
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
if (order.Id == model.Id) if (order.Id == model.Id)
@ -90,7 +111,7 @@ namespace AircraftPlantListImplement.Implements
/// <returns></returns> /// <returns></returns>
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.ImplementerId.HasValue)
{ {
return null; return null;
} }
@ -101,6 +122,14 @@ namespace AircraftPlantListImplement.Implements
{ {
return GetViewModel(order); return GetViewModel(order);
} }
if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status))
{
return GetViewModel(order);
}
if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId)
{
return GetViewModel(order);
}
} }
return null; return null;
} }

View File

@ -15,6 +15,7 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -31,6 +32,7 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Implementer)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -41,22 +43,38 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
return context.Orders else if (model.ImplementerId.HasValue)
{
return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.Where(x => x.Id == model.Id) .Include(x => x.Implementer)
.Where(x => x.ImplementerId == model.ImplementerId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
}
else if (model.Status != null)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Status.Equals(model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.ImplementerId.HasValue)
{ {
return null; return null;
} }
@ -64,8 +82,12 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? .Include(x => x.Implementer)
.GetViewModel; .FirstOrDefault(x =>
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status)
|| model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId
|| model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -28,29 +28,47 @@ namespace AircraftPlantFileImplement.Implements
{ {
return new(); return new();
} }
if (model.DateFrom.HasValue) else if (model.DateFrom.HasValue)
{ {
return _source.Orders return _source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)) .Select(x => GetViewModel(x))
.ToList(); .ToList();
} }
if (model.ClientId.HasValue && !model.Id.HasValue) else if (model.ClientId.HasValue && !model.Id.HasValue)
{ {
return _source.Orders return _source.Orders
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
else if (model.ImplementerId.HasValue)
{
return _source.Orders
.Where(x => x.ImplementerId == model.ImplementerId)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Status != null)
{
return _source.Orders
.Where(x => x.Status.Equals(model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.ImplementerId.HasValue)
{ {
return null; return null;
} }
return GetViewModel(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); var order = _source.Orders.FirstOrDefault(x =>
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status)
|| model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId
|| model.Id.HasValue && x.Id == model.Id);
return order?.GetViewModel != null ? order.GetViewModel : null;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {