using demo_trade.Data.RemoteData.Entity; using demo_trade.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Order = demo_trade.Data.RemoteData.Entity.Order; namespace demo_trade.Data.Repository { public class SQLOrderManagerRepository : IOrderManagerRepository { private TradeContext _tradeContext; public void Dispose() { GC.SuppressFinalize(this); } public SQLOrderManagerRepository() { _tradeContext = new TradeContext(); } public bool EditRangeOrders(List orders) { using var transaction = _tradeContext.Database.BeginTransaction(); try { foreach (var item in orders) { var order = _tradeContext.Orders.Find(item.OrderId); if (item.OrderStatus == null) continue; if (order.Orderstatus != item.OrderStatus) order.Orderstatus = item.OrderStatus; if (item.OrderDeliveryDate == null) continue; if (order.Orderdeliverydate != item.OrderDeliveryDate) order.Orderdeliverydate = item.OrderDeliveryDate.Value; _tradeContext.SaveChanges(); } transaction.Commit(); return true; } catch (Exception ex) { return false; } } public List GetAllOrders() { return _tradeContext.Orders.Include(it => it.Orderproducts).ThenInclude(it => it.ProductarticlenumberNavigation).Include(it => it.OrderpickuppointNavigation).ToList(); } } }