示例#1
0
 public void MoveOrder(int orderId, int newWarehouseId)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             Orders        order   = db.Orders.Where(o => o.id_order == orderId).First();
             Shipp_history history = db.Shipp_history.Where(h => h.id_order == orderId && h.send == false).First();
             history.send = true;
             db.SaveChanges();
             Shipp_history newHistory = new Shipp_history()
             {
                 id_partner     = order.id_recipient,
                 id_order       = order.id_order,
                 id_warehouse   = newWarehouseId,
                 send_date      = order.sending_date,
                 receiving_date = order.recevening_date,
                 send           = false
             };
             db.Shipp_history.Add(newHistory);
             db.SaveChanges();
             transaction.Commit();
         }
         catch
         {
             transaction.Rollback();
             throw;
         }
     }
 }
示例#2
0
        private ShippHistoryDto GetHistoryDto(Shipp_history history)
        {
            ShippHistoryDto historyDto = new ShippHistoryDto()
            {
                WarehouseTitle = history.Warehouses.title,
                ReceivingDate  = history.receiving_date,
                SendingDate    = history.send_date,
                Send           = history.send
            };

            return(historyDto);
        }
示例#3
0
        public Shipp_history AddShippingHistory(Orders order)
        {
            Shipp_history history = new Shipp_history()
            {
                id_order       = order.id_order,
                id_partner     = order.id_recipient,
                receiving_date = order.recevening_date,
                send_date      = order.sending_date,
                send           = false
            };
            int?wareHouseId = order.Products.ToArray()[0].id_warehouse;

            history.id_warehouse = wareHouseId;
            return(history);
        }
示例#4
0
        public OrderDto GetOrderDto(Orders order)
        {
            OrderDto orderDto = new OrderDto()
            {
                OrderId       = order.id_order,
                ReceivingDate = order.recevening_date,
                SendingDate   = order.sending_date
            };
            Shipp_history history   = db.Shipp_history.Where(sh => sh.id_order == order.id_order && sh.send == false).First();
            Warehouses    warehouse = db.Warehouses.Where(w => w.id_warehouse == history.id_warehouse).First();

            orderDto.CurrentWarehouseTitle = warehouse.title;
            foreach (Products product in order.Products)
            {
                ProductDto productDto = ProductToProductDto(product);
                orderDto.Products.Add(productDto);
            }
            return(orderDto);
        }
示例#5
0
        public void MakeOrder(PartnerDto partnerDto)
        {
            CargoDataBase db = new CargoDataBase();

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Orders order = new Orders();
                    order.id_recipient = partnerDto.Id;
                    order.sending_date = DateTime.Now;
                    DateTime receivDay = DateTime.Now.AddDays(10);
                    order.recevening_date = receivDay;
                    order.price           = 0;
                    order = db.Orders.Add(order);
                    db.SaveChanges();
                    foreach (int id in partnerDto.ItemsId)
                    {
                        Products product = db.Products.Where(p => p.id_product == id).First();
                        order.Products.Add(product);
                        order.price += product.weight;
                    }
                    db.SaveChanges();
                    Shipp_history history = shipHistoryManager.AddShippingHistory(order);
                    db.Shipp_history.Add(history);
                    db.SaveChanges();
                    transaction.Commit();
                    partnerDto.ItemsId.Clear();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }