merge lab5 with lab6
This commit is contained in:
commit
93d4ff0c66
@ -22,12 +22,15 @@ namespace FlowerShopDatabaseImplement.Implements
|
|||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new FlowerShopDatabase();
|
using var context = new FlowerShopDatabase();
|
||||||
if (model.Id.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
return context.Orders.Where(x => x.Id == model.Id).Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
return context.Orders
|
||||||
if (model.ClientId.HasValue)
|
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
return context.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
&& (!model.ClientId.HasValue || x.ClientId == model.ClientId))
|
||||||
return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).
|
.Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
||||||
Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
return context.Orders
|
||||||
|
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|
||||||
|
|| (model.ClientId.HasValue && x.ClientId == model.ClientId))
|
||||||
|
.Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
|
@ -19,14 +19,17 @@ namespace FlowerShopFileImplement.Implements
|
|||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (model.Id.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
return source.Orders.Where(x => x.Id == model.Id)
|
{
|
||||||
.Select(x => GetViewModel(x))
|
return source.Orders
|
||||||
|
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) && (!model.ClientId.HasValue || x.ClientId == model.ClientId))
|
||||||
|
.Select(GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
return source.Orders
|
||||||
|
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.ClientId == model.ClientId))
|
||||||
|
.Select(GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
if (model.ClientId.HasValue)
|
|
||||||
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList();
|
|
||||||
return source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).
|
|
||||||
Select(x => GetViewModel(x)).ToList();
|
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@ using FlowerShopContracts.SearchModels;
|
|||||||
using FlowerShopContracts.StoragesContracts;
|
using FlowerShopContracts.StoragesContracts;
|
||||||
using FlowerShopContracts.ViewModels;
|
using FlowerShopContracts.ViewModels;
|
||||||
using FlowerShopListImplement.Models;
|
using FlowerShopListImplement.Models;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace FlowerShopListImplement.Implements
|
namespace FlowerShopListImplement.Implements
|
||||||
{
|
{
|
||||||
@ -24,41 +25,17 @@ namespace FlowerShopListImplement.Implements
|
|||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
if (model.DateFrom.HasValue)
|
||||||
if (model == null || !model.Id.HasValue)
|
|
||||||
{
|
{
|
||||||
return result;
|
return _source.Orders
|
||||||
|
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) && (!model.ClientId.HasValue || x.ClientId == model.ClientId))
|
||||||
|
.Select(x => AttachNames(x.GetViewModel))
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
if (model.ClientId.HasValue)
|
return _source.Orders
|
||||||
{
|
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.ClientId == model.ClientId))
|
||||||
foreach (var order in _source.Orders)
|
.Select(x => AttachNames(x.GetViewModel))
|
||||||
{
|
.ToList();
|
||||||
if (order.Id == model.Id && order.ClientId == model.ClientId)
|
|
||||||
{
|
|
||||||
result.Add(AttachNames(order.GetViewModel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else if (model.ImplementerId.HasValue)
|
|
||||||
{
|
|
||||||
foreach (var order in _source.Orders)
|
|
||||||
{
|
|
||||||
if (order.Id == model.Id && order.ImplementerId == model.ImplementerId)
|
|
||||||
{
|
|
||||||
result.Add(AttachNames(order.GetViewModel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
foreach (var order in _source.Orders)
|
|
||||||
{
|
|
||||||
if (order.Id == model.Id && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
|
||||||
{
|
|
||||||
result.Add(AttachNames(order.GetViewModel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
@ -135,14 +112,6 @@ namespace FlowerShopListImplement.Implements
|
|||||||
model.ClientFIO = client.ClientFIO;
|
model.ClientFIO = client.ClientFIO;
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
foreach (var implementer in _source.Implementers)
|
|
||||||
{
|
|
||||||
if (implementer.Id == model.ImplementerId)
|
|
||||||
{
|
|
||||||
model.ImplementerFIO = implementer.ImplementerFIO;
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,14 @@ namespace FlowerShopRestApi.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<OrderViewModel>? GetOrders(int clientId)
|
public List<OrderViewModel>? GetOrders(int? clientId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _order.ReadList(new OrderSearchModel
|
return _order.ReadList(clientId != null ? new OrderSearchModel
|
||||||
{
|
{
|
||||||
ClientId = clientId
|
ClientId = clientId
|
||||||
});
|
} : null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user