コード例 #1
0
 public OrderDTO GetOrderByID(int id)
 {
     using (var db = new OrderDAL())
     {
         var order = db.tblOrders.FirstOrDefault(o => o.ID == id);
         return(_mapper.Map <OrderDTO>(order));
     }
 }
コード例 #2
0
 public List <OrderDTO> GetAllOrders()
 {
     using (var db = new OrderDAL())
     {
         var orders = db.tblOrders.ToList();
         return(_mapper.Map <List <OrderDTO> >(orders));
     }
 }
コード例 #3
0
 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();
     }
 }
コード例 #4
0
 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);
 }
コード例 #5
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();
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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");
            }
        }