ISEbd-21 Melnikov I.O. Lab Work 05 Base #11

Closed
Igor-Melnikov wants to merge 15 commits from lab5 into lab4
3 changed files with 52 additions and 14 deletions
Showing only changes of commit 7049e5fca4 - Show all commits

View File

@ -24,15 +24,26 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return new();
}
using var context = new BlacksmithWorkshopDatabase();
List<OrderViewModel> orderList = context.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
List<OrderViewModel> orderList = new();
if (model.Id.HasValue) //сначала ищем по Id
{
orderList = context.Orders
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.DateFrom.HasValue && model.DateTo.HasValue) //если у модели нет Id, ищем по датам
{
orderList = context.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
foreach (var order in orderList)
{
string manufactureName = context.Manufactures

View File

@ -27,14 +27,25 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return new();
}
return source.Orders
if (model.Id.HasValue)//сначала ищем по Id
{
return source.Orders
.Where(x => x.Id == model.Id)
.Select(x => AddManufactureName(x.GetViewModel))
.ToList();
}
else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если Id в модели нет, ищем по датам
{
return source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => AddManufactureName(x.GetViewModel))
.ToList();
}
return new();//если нет ни того, ни другого, возвращаем пустой список
}
public OrderViewModel? GetElement(OrderSearchModel model)
{

View File

@ -28,18 +28,34 @@ namespace BlacksmithWorkshopListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return result;
}
foreach (var order in _source.Orders)
if (model.Id.HasValue)//сначала ищем по Id
{
if (model.Id.HasValue && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
foreach (var order in _source.Orders)
{
OrderViewModel vm = order.GetViewModel;
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
result.Add(vm);
if (model.Id == order.Id)
{
OrderViewModel vm = order.GetViewModel;
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
result.Add(vm);
}
}
}
else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если у модели нет Id, ищем по датам
{
foreach (var order in _source.Orders)
{
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
{
OrderViewModel vm = order.GetViewModel;
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
result.Add(vm);
}
}
}
return result;