Add Client to storage filters

This commit is contained in:
Viltskaa 2023-03-26 17:19:08 +04:00
parent 92139ca325
commit 242352a50b
5 changed files with 18 additions and 12 deletions

View File

@ -5,5 +5,6 @@
public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ClientId { get; set; }
}
}

View File

@ -7,7 +7,7 @@ namespace SushiBarContracts.StoragesContracts
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
List<OrderViewModel> GetFilteredList(OrderSearchModel? model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);

View File

@ -14,15 +14,12 @@ namespace SushiBarDatabaseImplement.Implements
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
if (element == null) return null;
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return element.GetViewModel;
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
@ -39,10 +36,10 @@ namespace SushiBarDatabaseImplement.Implements
?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
public List<OrderViewModel> GetFilteredList(OrderSearchModel? model)
{
if (model is null)
return new();
return new List<OrderViewModel>();
using var context = new SushiBarDatabase();
if (!model.Id.HasValue)
@ -53,6 +50,14 @@ namespace SushiBarDatabaseImplement.Implements
.ToList();
}
if (!model.ClientId.HasValue)
{
return context.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders
.Where(x => x.Id == model.Id)

View File

@ -38,7 +38,7 @@ namespace SushiBarFileImplement.Implements
?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
public List<OrderViewModel> GetFilteredList(OrderSearchModel? model)
{
if (!model.Id.HasValue)
{

View File

@ -44,7 +44,7 @@ namespace SushibarListImplement.Implements
return null;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
public List<OrderViewModel> GetFilteredList(OrderSearchModel? model)
{
List<OrderViewModel> list = new();
if (!model.Id.HasValue || model.Id == 0)