demo_trade/Data/Repository/SQLOrderClientRepository.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2024-10-04 12:41:04 +00:00
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<Orderproduct> 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<Order> GetAllOrders()
{
throw new NotImplementedException();
}
public int GetNumberForNewOrder()
{
return _tradeContext.Orders.Max(it => it.Orderid) + 1;
}
}
}