예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserName,Password,FullName,Sex,PhoneNumber,Email,Brithday,Address,JoinDate,IdRole")] UserInformation userInformation)
        {
            if (id != userInformation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(userInformation);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserInformationExists(userInformation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdRole"] = new SelectList(context.Roles, "Id", "Role1", userInformation.IdRole);
            return(View(userInformation));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CatalogName,CatalogDetails,DateCreated")] Catalog catalog)
        {
            if (id != catalog.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(catalog);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CatalogExists(catalog.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(catalog));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,IdUser,OrderDate,TotalCost,DeliveryAddress,DeliveryDate")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(order);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdUser"] = new SelectList(context.UserInformations, "Id", "Address", order.IdUser);
            return(View(order));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ComboName,ComboDetails,TotalCost,Price,IdCatalog,DateCreated")] Combo combo)
        {
            if (id != combo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(combo);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComboExists(combo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdCatalog"] = new SelectList(context.Catalogs, "Id", "CatalogDetails", combo.IdCatalog);
            return(View(combo));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductName,Amount,Price,Detail,IdClassify,DateCreated")] Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(product);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdClassify"] = new SelectList(context.Classifies, "Id", "ClassifyDetail", product.IdClassify);
            return(View(product));
        }
        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"));
        }