fix
This commit is contained in:
parent
e9c62b734f
commit
0e574729f3
@ -24,21 +24,11 @@ namespace GiftShopDatabaseImplement.Implements
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new GiftShopDatabase();
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status.Equals(model.Status))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return context.Orders
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
using var context = new GiftShopDatabase();
|
||||
return context.Orders.Include(x => x.Gift).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(
|
||||
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
@ -47,35 +37,19 @@ namespace GiftShopDatabaseImplement.Implements
|
||||
return new();
|
||||
}
|
||||
using var context = new GiftShopDatabase();
|
||||
if (model.DateTo != null && model.DateFrom != null && model.ClientId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo && x.ClientId == model.ClientId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.DateTo != null && model.DateFrom != null)
|
||||
{
|
||||
return context.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.ClientId.HasValue)
|
||||
return context.Orders
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
||||
return context.Orders
|
||||
.Where(x => x.Status == model.Status)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Orders
|
||||
.Include(x => x.Gift)
|
||||
.Include(x => x.Client).Include(x => x.Implementer).Where(x => (
|
||||
(!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
|
||||
&&
|
||||
(!model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
)
|
||||
)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
@ -86,12 +60,12 @@ namespace GiftShopDatabaseImplement.Implements
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
using var context = new GiftShopDatabase();
|
||||
var newOrder = Order.Create(model, context);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new GiftShopDatabase();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace GiftShopDatabaseImplement.Models
|
||||
public Client Client { get; set; }
|
||||
public Implementer? Implementer { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
public static Order? Create(OrderBindingModel? model, GiftShopDatabase context)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -49,15 +49,19 @@ namespace GiftShopDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
GiftId = model.GiftId,
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId,
|
||||
GiftName = model.GiftName,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
DateImplement = model.DateImplement,
|
||||
Gift = context.Gifts.FirstOrDefault(x => x.Id == model.GiftId),
|
||||
ClientId = model.ClientId,
|
||||
Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId),
|
||||
ImplementerId = model.ImplementerId,
|
||||
Implementer = (model.ImplementerId.HasValue ? context.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId)
|
||||
: null),
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
@ -83,15 +87,15 @@ namespace GiftShopDatabaseImplement.Models
|
||||
GiftId = GiftId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
||||
GiftName = context.Gifts.FirstOrDefault(x => x.Id == GiftId)?.GiftName ?? string.Empty,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
GiftName = Gift.GiftName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
|
||||
};
|
||||
ImplementerFIO = (Implementer != null ? Implementer.ImplementerFIO : string.Empty)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace GiftShopFileImplement.Implements
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
|
||||
return element.GetViewModel;
|
||||
return AccessStorage(element.GetViewModel);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -37,27 +37,30 @@ namespace GiftShopFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
return AccessStorage(source.Orders
|
||||
.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(model.ImplementerId.HasValue &&
|
||||
x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel);
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Where(x => (
|
||||
(!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
|
||||
&&
|
||||
(!model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
)
|
||||
)
|
||||
.Select(x => AccessStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => x.GetViewModel).ToList();
|
||||
return source.Orders.Select(x => AccessStorage(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
@ -73,7 +76,7 @@ namespace GiftShopFileImplement.Implements
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
|
||||
return newOrder.GetViewModel;
|
||||
return AccessStorage(newOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -88,7 +91,22 @@ namespace GiftShopFileImplement.Implements
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
|
||||
return order.GetViewModel;
|
||||
return AccessStorage(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
public OrderViewModel AccessStorage(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
var gift = source.Gifts.FirstOrDefault(x => x.Id == model.Id);
|
||||
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId);
|
||||
if (gift != null)
|
||||
model.GiftName = gift.GiftName;
|
||||
if (client != null)
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
if (implementer != null)
|
||||
model.ImplementerFIO = implementer.ImplementerFIO;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,46 +30,37 @@ namespace GiftShopListImplement.Implements
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
{
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if ((model.Id.HasValue && order.Id == model.Id) ||
|
||||
(model.ImplementerId.HasValue &&
|
||||
order.ImplementerId == model.ImplementerId && order.Status == model.Status))
|
||||
{
|
||||
return AccessStorage(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
List<OrderViewModel> list = new();
|
||||
if (!model.Id.HasValue || model.Id == 0)
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
foreach (Order order in _source.Orders)
|
||||
if ((!model.Id.HasValue || order.Id == model.Id) &&
|
||||
(!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) &&
|
||||
(!model.DateTo.HasValue || order.DateCreate <= model.DateTo)
|
||||
&&
|
||||
(!model.ClientId.HasValue || order.ClientId == model.ClientId))
|
||||
{
|
||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||
{
|
||||
list.Add(order.GetViewModel);
|
||||
}
|
||||
result.Add(AccessStorage(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
list.Add(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
@ -77,7 +68,7 @@ namespace GiftShopListImplement.Implements
|
||||
List<OrderViewModel> list = new();
|
||||
foreach (Order order in _source.Orders)
|
||||
{
|
||||
list.Add(order.GetViewModel);
|
||||
list.Add(AccessStorage(order.GetViewModel));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@ -113,5 +104,20 @@ namespace GiftShopListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public OrderViewModel AccessStorage(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
var gift = _source.Gifts.FirstOrDefault(x => x.Id == model.Id);
|
||||
var client = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
var implementer = _source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId);
|
||||
if (gift != null)
|
||||
model.GiftName = gift.GiftName;
|
||||
if (client != null)
|
||||
model.ClientFIO = client.ClientFIO;
|
||||
if (implementer != null)
|
||||
model.ImplementerFIO = implementer.ImplementerFIO;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user