public IActionResult DatHang(int IdUser, Decimal TotalCost, String DeliveryAddress, DateTime DeliveryDate)
        {
            Order order = new Order();

            order.IdUser          = IdUser;
            order.TotalCost       = TotalCost;
            order.DeliveryAddress = DeliveryAddress;
            order.DeliveryDate    = DeliveryDate;
            context.Add(order);
            context.SaveChanges();
            var carts = context.Carts.Include(t => t.IdComboNavigation).Include(t => t.IdProductNavigation).Where(t => t.IdUser == IdUser);

            Console.WriteLine(order.Id);

            foreach (var item in carts)
            {
                if (item.IdCombo == null)
                {
                    OrdersDetail ordersDetail = new OrdersDetail()
                    {
                        IdOrders = order.Id
                        ,
                        IdCombo   = item.IdCombo,
                        IdProduct = item.IdProduct,
                        Amount    = item.Amount,
                        Price     = item.IdProductNavigation.Price
                    };
                    var ud = context.Products.Find(ordersDetail.IdProduct);
                    ud.Amount = ud.Amount - ordersDetail.Amount;
                    contextWrite.Add(ordersDetail);
                    contextWrite.SaveChanges();
                    contextWrite.Update(ud);
                    contextWrite.SaveChanges();
                    contextWrite.Remove(item);
                    contextWrite.SaveChanges();
                }
                else
                {
                    OrdersDetail ordersDetail = new OrdersDetail()
                    {
                        IdOrders = order.Id
                        ,
                        IdCombo   = item.IdCombo,
                        IdProduct = item.IdProduct,
                        Amount    = item.Amount,
                        Price     = item.IdComboNavigation.Price
                    };


                    contextWrite.Add(ordersDetail);
                    contextWrite.SaveChanges();
                    contextWrite.Remove(item);
                    contextWrite.SaveChanges();
                }
            }
            return(new JsonResult("Đặt hàng thành công"));
        }
Ejemplo n.º 2
0
        public void create(Warehouse warehouse)
        {
            sellingComponentsDBContext.Add(warehouse);
            var pd = sellingComponentsDBContext.Products.Find(warehouse.IdProduct);

            pd.Amount += warehouse.Amount;
            sellingComponentsDBContext.SaveChanges();
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,CatalogName,CatalogDetails,DateCreated")] Catalog catalog)
        {
            if (ModelState.IsValid)
            {
                context.Add(catalog);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(catalog));
        }
        public async Task <IActionResult> Create([Bind("Id,ClassifyName,ClassifyDetail,DateCreated")] Classify classify)
        {
            if (ModelState.IsValid)
            {
                context.Add(classify);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(classify));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,UserName,Password,FullName,Sex,PhoneNumber,Email,Brithday,Address,JoinDate,IdRole")] UserInformation userInformation)
        {
            if (ModelState.IsValid)
            {
                context.Add(userInformation);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdRole"] = new SelectList(context.Roles, "Id", "Role1", userInformation.IdRole);
            return(View(userInformation));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,IdUser,OrderDate,TotalCost,DeliveryAddress,DeliveryDate")] Order order)
        {
            if (ModelState.IsValid)
            {
                context.Add(order);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdUser"] = new SelectList(context.UserInformations, "Id", "Address", order.IdUser);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("Id,ComboName,ComboDetails,TotalCost,Price,IdCatalog,DateCreated")] Combo combo)
        {
            if (ModelState.IsValid)
            {
                context.Add(combo);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdCatalog"] = new SelectList(context.Catalogs, "Id", "CatalogDetails", combo.IdCatalog);
            return(View(combo));
        }
 public void create(Classify classify)
 {
     sellingComponentsDBContext.Add(classify);
     sellingComponentsDBContext.SaveChanges();
 }
Ejemplo n.º 9
0
 public void create(Combo combo)
 {
     sellingComponentsDBContext.Add(combo);
     sellingComponentsDBContext.SaveChanges();
 }
Ejemplo n.º 10
0
 public void create(Product product)
 {
     sellingComponentsDBContext.Add(product);
     sellingComponentsDBContext.SaveChanges();
 }
 public void create(Catalog catalog)
 {
     sellingComponentsDBContext.Add(catalog);
     sellingComponentsDBContext.SaveChanges();
 }