using demo_trade.Data.RemoteData.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace demo_trade.Data.Repository { public class SQLOrderClientRepository : IOrderRepository, IDisposable { private TradeContext _tradeContext; public SQLOrderClientRepository() { _tradeContext = new TradeContext(); } public Order CreateOrder(Order order, List orderproducts) { using var transaction = _tradeContext.Database.BeginTransaction(); try { var createdOrder = _tradeContext.Add(order); _tradeContext.SaveChanges(); foreach (var product in orderproducts) { _tradeContext.Add(new Orderproduct { Orderid = order.Orderid, Productarticlenumber = product.Productarticlenumber, ProductCount = product.ProductCount }); } _tradeContext.SaveChanges(); transaction.Commit(); } catch (Exception ex) { } return order; } public void Dispose() { GC.SuppressFinalize(this); } public List GetAllOrders() { throw new NotImplementedException(); } public int GetNumberForNewOrder() { return _tradeContext.Orders.Max(it => it.Orderid) + 1; } } }