Exemple #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            ChiTietDonHangHuy chiTietDonHangHuy = db.ChiTietDonHangHuys.Find(id);

            db.ChiTietDonHangHuys.Remove(chiTietDonHangHuy);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #2
0
 public ActionResult Edit([Bind(Include = "MaChiTietDonHangHuy,MaSanPham,MaHuyDon,SoLuong,TinhTrang")] ChiTietDonHangHuy chiTietDonHangHuy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chiTietDonHangHuy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaHuyDon  = new SelectList(db.HuyDonHangs, "MaHuyDon", "MaDonHang", chiTietDonHangHuy.MaHuyDon);
     ViewBag.MaSanPham = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", chiTietDonHangHuy.MaSanPham);
     return(View(chiTietDonHangHuy));
 }
Exemple #3
0
        // GET: ChiTietDonHangHuys/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHangHuy chiTietDonHangHuy = db.ChiTietDonHangHuys.Find(id);

            if (chiTietDonHangHuy == null)
            {
                return(HttpNotFound());
            }
            return(View(chiTietDonHangHuy));
        }
Exemple #4
0
        // GET: ChiTietDonHangHuys/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDonHangHuy chiTietDonHangHuy = db.ChiTietDonHangHuys.Find(id);

            if (chiTietDonHangHuy == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaHuyDon  = new SelectList(db.HuyDonHangs, "MaHuyDon", "MaDonHang", chiTietDonHangHuy.MaHuyDon);
            ViewBag.MaSanPham = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", chiTietDonHangHuy.MaSanPham);
            return(View(chiTietDonHangHuy));
        }
Exemple #5
0
        public ActionResult Denied(int?maGH)
        {
            Order order = db.Orders.FirstOrDefault(m => m.OrderID == maGH);

            if (order.MaKH != 3)
            {
                KhachHang khachHang = db.KhachHangs.Find(order.MaKH);
                khachHang.DiemTichLuy -= order.TongTien / 1000;
                db.SaveChanges();
                if (khachHang.DiemTichLuy >= 1000000)
                {
                    khachHang.MaLoaiKH = 5;
                    db.SaveChanges();
                }
                else if (khachHang.DiemTichLuy >= 100000)
                {
                    khachHang.MaLoaiKH = 4;
                    db.SaveChanges();
                }
                else if (khachHang.DiemTichLuy >= 10000)
                {
                    khachHang.MaLoaiKH = 3;
                    db.SaveChanges();
                }
                else if (khachHang.DiemTichLuy >= 1000)
                {
                    khachHang.MaLoaiKH = 2;
                    db.SaveChanges();
                }
                else
                {
                    khachHang.MaLoaiKH = 1;
                    db.SaveChanges();
                }
            }



            var chiTietGioHang = db.ChiTietGioHangs.Where(s => s.OrderID == maGH).ToList();

            foreach (var item in chiTietGioHang)
            {
                SanPham sanPham = db.SanPhams.Find(item.MaSanPham);
                sanPham.SoLuong   = sanPham.SoLuong + item.SoLuong;
                sanPham.TinhTrang = "Hiển Thị";
                db.SaveChanges();

                HuyDonHang huyDonHang = new HuyDonHang();
                huyDonHang.MaDonHang   = order.OrderID.ToString();
                huyDonHang.MaKH        = order.MaKH;
                huyDonHang.TongTien    = order.TongTien;
                huyDonHang.NgayXacNhan = DateTime.Parse(DateTime.Now.ToShortDateString());
                huyDonHang.TinhTrang   = "Đã Từ Chối";
                db.HuyDonHangs.Add(huyDonHang);
                db.SaveChanges();

                ChiTietDonHangHuy chiTietDonHangHuy = new ChiTietDonHangHuy();
                chiTietDonHangHuy.MaHuyDon  = huyDonHang.MaHuyDon;
                chiTietDonHangHuy.MaSanPham = item.MaSanPham;
                chiTietDonHangHuy.SoLuong   = item.SoLuong;
                chiTietDonHangHuy.TinhTrang = "Đã Từ Chối";
                db.ChiTietDonHangHuys.Add(chiTietDonHangHuy);
                db.SaveChanges();

                ChiTietGioHang chiTietGioHangXoa = db.ChiTietGioHangs.FirstOrDefault(m => m.OrderID == maGH);
                db.ChiTietGioHangs.Remove(chiTietGioHangXoa);
                db.SaveChanges();
            }

            Order deleteOrder = db.Orders.Find(maGH);

            db.Orders.Remove(deleteOrder);
            db.SaveChanges();


            return(RedirectToAction("Index"));
        }