OrderStorage changed lab 6
This commit is contained in:
parent
30394150d8
commit
374bc28468
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using JewelryStoreDataModels.Enums;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -13,5 +14,7 @@ namespace JewelryStoreContracts.SearchModels
|
|||||||
|
|
||||||
public DateTime? DateFrom { get; set; }
|
public DateTime? DateFrom { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
|
public int? ImplementerId { get; set; }
|
||||||
|
public List<OrderStatus>? Statuses { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
using var context = new JewelryStoreDataBase();
|
using var context = new JewelryStoreDataBase();
|
||||||
|
|
||||||
var element = context.Orders.Include(x => x.Jewel)
|
var element = context.Orders.Include(x => x.Jewel)
|
||||||
.Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id);
|
.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
@ -41,39 +41,55 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
|
|
||||||
using var context = new JewelryStoreDataBase();
|
using var context = new JewelryStoreDataBase();
|
||||||
|
|
||||||
return context.Orders.Include(x => x.Jewel)
|
return context.Orders
|
||||||
.Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x =>
|
||||||
|
(model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) &&
|
||||||
|
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId ||
|
||||||
|
model.Id.HasValue && x.Id == model.Id
|
||||||
|
)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var result = GetElement(model);
|
||||||
|
return result != null ? new() { result } : new();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new JewelryStoreDataBase();
|
||||||
|
IQueryable<Order>? queryWhere = null;
|
||||||
|
|
||||||
|
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||||
|
{
|
||||||
|
queryWhere = context.Orders
|
||||||
|
.Where(x => model.DateFrom <= x.DateCreate.Date &&
|
||||||
|
x.DateCreate.Date <= model.DateTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (model.Statuses != null)
|
||||||
|
{
|
||||||
|
queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (model.ClientId.HasValue)
|
||||||
|
{
|
||||||
|
queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new JewelryStoreDataBase();
|
|
||||||
if (model.DateFrom.HasValue)
|
return queryWhere
|
||||||
{
|
|
||||||
return context.Orders
|
|
||||||
.Include(x => x.Jewel)
|
|
||||||
.Include(x => x.Client)
|
|
||||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
else if (model.ClientId.HasValue)
|
|
||||||
return context.Orders
|
|
||||||
.Include(x => x.Jewel)
|
|
||||||
.Include(x => x.Client)
|
.Include(x => x.Client)
|
||||||
.Where(x => x.ClientId == model.ClientId)
|
.Include(x => x.Implementer)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
return context.Orders
|
|
||||||
.Include(x => x.Jewel)
|
|
||||||
.Include(x => x.Client)
|
|
||||||
.Where(x => x.Id == model.Id)
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
@ -81,7 +97,7 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
using var context = new JewelryStoreDataBase();
|
using var context = new JewelryStoreDataBase();
|
||||||
|
|
||||||
return context.Orders.Include(x => x.Jewel)
|
return context.Orders.Include(x => x.Jewel)
|
||||||
.Include(x => x.Client).Select(x => x.GetViewModel).ToList();
|
.Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
@ -98,7 +114,11 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return newOrder.GetViewModel;
|
return context.Orders.Include(x => x.Jewel)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
@ -106,7 +126,7 @@ namespace JewelryStoreDatabaseImplement.Implements
|
|||||||
using var context = new JewelryStoreDataBase();
|
using var context = new JewelryStoreDataBase();
|
||||||
|
|
||||||
var order = context.Orders.Include(x => x.Jewel)
|
var order = context.Orders.Include(x => x.Jewel)
|
||||||
.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
|
.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user