Ejemplo n.º 1
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;
                }
            }
        }