コード例 #1
0
        public async Task <IActionResult> PutProduct(string id, Product product)
        {
            if (id != product.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutCategory(string id, Category category)
        {
            if (id != category.CategoryId)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutBrand(string id, Brand brand)
        {
            if (id != brand.BrandId)
            {
                return(BadRequest());
            }

            _context.Entry(brand).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        public void UpdateTrangThaiDonHang(int maDatHang)
        {
            DATHANG datHang = context.DATHANGs.
                              Include(t => t.CHITIETDATHANGs).
                              FirstOrDefault(t => t.Id_DatHang == maDatHang && t.TrangThai == 1);

            if (datHang == null)
            {
                return;
            }
            // kiem tra sl ton
            KiemTraSLTon(datHang);
            // update đặt  hàng
            datHang.TrangThai            = 2; //Xuất hoá đơn trạng thái ==2: dang giao
            datHang.NgayGiao             = DateTime.Now;
            context.Entry(datHang).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();
        }
コード例 #5
0
        public ActionResult fillFormCustomer(string id, bool Accumulated)
        {
            List <ProductCart> productCarts = GetProductCarts();
            var strimId      = id.Trim(',');
            var listHadCheck = strimId.Split(',').Select(int.Parse).ToList();

            //lấy ra sản phẩm trong giỏ hàng từ các sản phẩm đã chọn
            var products = productCarts.Where(x => listHadCheck.Contains(x.Id_SanPham));
            // tổng tiền trong giổ hàng
            var sumTotal = products.Sum(x => x.soluong * x.giagiam);

            var customerlogin = SessionUser.GetSession();
            var customer      = db.KHACHHANGs.Where(x => x.Id_KhachHang == customerlogin.Id).FirstOrDefault();
            var address       = db.DIACHIs.Where(x => x.Id_KhachHang == customer.Id_KhachHang && x.TrangThai == true).FirstOrDefault();


            DATHANG orderForm = new DATHANG
            {
                NgayDat      = DateTime.Now,
                TrangThai    = 1,
                DiaChiGiao   = address.DiaChi,
                SoDienThoai  = address.SoDienThoai,
                Id_KhachHang = customer.Id_KhachHang,
                TenNguoiNhan = address.TenKhachHang,
                // 50 tiền ship
                TongTien = sumTotal + 50
            };
            var aNewOder = db.DATHANGs.Add(orderForm);

            orderForm.Id_DatHang = aNewOder.Id_DatHang;
            // nếu nó có check thì lưu thêm cột giảm giá
            if (Accumulated == true)
            {
                orderForm.TongTienSauGiamGia = orderForm.TongTien - (double.Parse(customer.DiemTichLuy.ToString()) * 1000);
                orderForm.DiemTichLuy        = customer.DiemTichLuy;
                customer.DiemTichLuy         = 0;
                db.Entry(customer).State     = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            foreach (var product in products)
            {
                CHITIETDATHANG detailOrder = new CHITIETDATHANG();
                detailOrder.Id_DatHang = aNewOder.Id_DatHang;
                detailOrder.Id_SanPham = product.Id_SanPham;
                detailOrder.SoLuong    = product.soluong;
                detailOrder.GiaBan     = product.giagiam;
                detailOrder.ThanhTien  = product.soluong * product.giagiam;
                detailOrder.TrangThai  = true;
                db.CHITIETDATHANGs.Add(detailOrder);
            }

            db.SaveChanges();
            return(RedirectToAction("succesBill", "PayForBill", new { idDatHang = orderForm.Id_DatHang }));
        }
コード例 #6
0
 public ActionResult Edit(int id, LOAISANPHAM collection)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             db.Entry(collection).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(collection));
     }
     catch
     {
         return(View());
     }
 }
コード例 #7
0
        public JsonResult changeAddress(int IdAddress, int IdCustomer)
        {
            var address = db.DIACHIs.Where(x => x.Id_KhachHang == IdCustomer).ToList();

            if (IdCustomer != 0)
            {
                foreach (var item in address)
                {
                    if (item.Id_DiaChi == IdAddress)
                    {
                        item.TrangThai = true;
                    }
                    else
                    {
                        item.TrangThai = false;
                    }
                    db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
        }