Ejemplo n.º 1
0
        public void DeleteProduct(int productId)
        {
            Products product = db.Products.Where(p => p.id_product == productId).First();

            db.Products.Remove(product);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
 public void DeleteOrder(int orderId)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             Orders order = db.Orders.Where(o => o.id_order == orderId).First();
             List <Shipp_history> histories = db.Shipp_history.Where(h => h.id_order == orderId).ToList();
             histories.ForEach(h => db.Shipp_history.Remove(h));
             order.Products.Clear();
             db.SaveChanges();
             db.Orders.Remove(order);
             db.SaveChanges();
             transaction.Commit();
         }
         catch
         {
             transaction.Rollback();
             throw;
         }
     }
 }
Ejemplo n.º 3
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;
                }
            }
        }
Ejemplo n.º 4
0
 public void AddWarehouse(Warehouses warehouses)
 {
     db.Warehouses.Add(warehouses);
     db.SaveChanges();
 }
Ejemplo n.º 5
0
 public void AddNewPartner(Partners partners)
 {
     db.Partners.Add(partners);
     db.SaveChanges();
 }