public OrderDTO GetOrderByID(int id) { using (var db = new OrderDAL()) { var order = db.tblOrders.FirstOrDefault(o => o.ID == id); return(_mapper.Map <OrderDTO>(order)); } }
public List <OrderDTO> GetAllOrders() { using (var db = new OrderDAL()) { var orders = db.tblOrders.ToList(); return(_mapper.Map <List <OrderDTO> >(orders)); } }
public void Update(OrderDTO order) { using (var db = new OrderDAL()) { var old = db.tblOrders.FirstOrDefault(o => o.ID == order.ID); old.ProductName = order.ProductName; old.CusmomerName = order.CusmomerName; old.Price = order.Price; old.OrderDate = order.OrderDate; db.SaveChanges(); } }
public int AddOrder(OrderDTO order) { if (order != null) { using (var db = new OrderDAL()) { var neworder = db.tblOrders.Add(_mapper.Map <tblOrder>(order)); db.SaveChanges(); return(neworder.ID); } } return(0); }
public void AddOrder(Order order) { using var _context = new Project0Context(_options); OrderDAL newOrder = new OrderDAL { StoreId = order.Store.ID, CustomerId = order.Customer.ID, TotalPrice = Convert.ToDecimal(order.TotalPrice), OrderTime = order.OrderTime, }; _context.Add(newOrder); _context.SaveChanges(); }
public int DeleteOrderByID(int id) { using (var db = new OrderDAL()) { var order = _mapper.Map <tblOrder>(GetOrderByID(id)); if (order != null) { db.Entry(order).State = EntityState.Deleted; db.SaveChanges(); return(0); } return(1); } }
public void UpdateOrder(Order order) { using var _context = new Project0Context(_options); OrderDAL toUpdate = _context.Orders.Find(order.ID); if (toUpdate != null) { toUpdate.TotalPrice = Convert.ToDecimal(order.TotalPrice); toUpdate.OrderTime = order.OrderTime; _context.Update(toUpdate); _context.SaveChanges(); } else { throw new Exception("Couldn't find order to update"); } }