Trabls
This commit is contained in:
parent
99b0e691c4
commit
858d42295b
@ -0,0 +1,82 @@
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.SearchModels;
|
||||
using ElectronicsShopContracts.StorageContracts;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using ElectronicsShopDataBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronicsShopDataBaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.ID == model.ID);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.ID.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Orders.FirstOrDefault(x =>
|
||||
(x.DateCreate == model.DateFrom && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.DateFrom.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
//Придумать решение
|
||||
return context.Orders.Where(x => x.Status.Contains(model.ID).Select(x => x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Orders.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newComponent = Order.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Orders.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.Orders.FirstOrDefault(x => x.ID == model.ID);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
{
|
||||
public int ID { get; set; }
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
public double Sum { get; set; }
|
||||
[Required]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[Required]
|
||||
|
Loading…
Reference in New Issue
Block a user