示例#1
0
        public ActionResult DeleteConfirmed(int id)
        {
            XacNhanDonHang xacNhanDonHang = db.XacNhanDonHangs.Find(id);

            db.XacNhanDonHangs.Remove(xacNhanDonHang);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
 public ActionResult Edit([Bind(Include = "MaDonHang,MaKH,VoucherID,TongTien,TinhTrang,NgayXacNhan,DiaChi,SDT,HoTen")] XacNhanDonHang xacNhanDonHang)
 {
     if (ModelState.IsValid)
     {
         db.Entry(xacNhanDonHang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaKH      = new SelectList(db.KhachHangs, "MaKH", "TenKH", xacNhanDonHang.MaKH);
     ViewBag.VoucherID = new SelectList(db.Vouchers, "VoucherID", "TenVoucher", xacNhanDonHang.VoucherID);
     return(View(xacNhanDonHang));
 }
示例#3
0
        // GET: XacNhanDonHangs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            XacNhanDonHang xacNhanDonHang = db.XacNhanDonHangs.Find(id);

            if (xacNhanDonHang == null)
            {
                return(HttpNotFound());
            }
            return(View(xacNhanDonHang));
        }
示例#4
0
        // GET: XacNhanDonHangs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            XacNhanDonHang xacNhanDonHang = db.XacNhanDonHangs.Find(id);

            if (xacNhanDonHang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaKH      = new SelectList(db.KhachHangs, "MaKH", "TenKH", xacNhanDonHang.MaKH);
            ViewBag.VoucherID = new SelectList(db.Vouchers, "VoucherID", "TenVoucher", xacNhanDonHang.VoucherID);
            return(View(xacNhanDonHang));
        }
示例#5
0
        public ActionResult Confirm(int?maGH)
        {
            Order          order = db.Orders.FirstOrDefault(m => m.OrderID == maGH);
            XacNhanDonHang tmp   = new XacNhanDonHang();

            tmp.MaKH        = order.MaKH;
            tmp.VoucherID   = order.VoucherID;
            tmp.TongTien    = order.TongTien;
            tmp.TinhTrang   = "Đã Xác Nhận";
            tmp.DiaChi      = order.DiaChi;
            tmp.SDT         = order.SDT;
            tmp.HoTen       = order.HoTen;
            tmp.NgayXacNhan = DateTime.Now;
            db.XacNhanDonHangs.Add(tmp);
            db.SaveChanges();

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

            foreach (var item in chiTietGioHang)
            {
                OrderConfirmedDetail orderConfirmedDetail = new OrderConfirmedDetail();
                orderConfirmedDetail.MaSanPham   = item.MaSanPham;
                orderConfirmedDetail.SoLuong     = item.SoLuong;
                orderConfirmedDetail.MaDonHang   = tmp.MaDonHang;
                orderConfirmedDetail.TinhTrang   = tmp.TinhTrang;
                orderConfirmedDetail.NgayXacNhan = DateTime.Now;
                db.OrderConfirmedDetails.Add(orderConfirmedDetail);
                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"));
        }
示例#6
0
        // GET: XacNhanDonHangs
        public ActionResult Index(string startDay, string endDay, string phoneNumber, string status)
        {
            long tongDoanhThu = 0;

            for (int i = 1; i <= db.XacNhanDonHangs.LongCount(); i++)
            {
                XacNhanDonHang xacNhanDonHang = new XacNhanDonHang();
                xacNhanDonHang = db.XacNhanDonHangs.Find(i);
                if (xacNhanDonHang.TinhTrang == "Đã Giao Hàng")
                {
                    tongDoanhThu = tongDoanhThu + xacNhanDonHang.TongTien;
                }
            }

            ViewBag.TongDoanhThu = tongDoanhThu;

            Session["tmp"] = "9";
            var result = from g in db.XacNhanDonHangs
                         join c in db.OrderConfirmedDetails on g.MaDonHang equals c.MaDonHang
                         join s in db.SanPhams on c.MaSanPham equals s.MaSanPham
                         select new Tmp
            {
                Hinh       = s.Hinh,
                TenSanPham = s.TenSanPham,
                SoLuong    = c.SoLuong,
                MaDonHang  = g.MaDonHang,
            };

            ViewBag.ds = result;

            if (status != null)
            {
                var xacNhanDonHangs = db.XacNhanDonHangs.Include(k => k.KhachHang).Include(k => k.Voucher).Where(x => x.TinhTrang == status);
                return(View(xacNhanDonHangs.ToList()));
            }

            if (phoneNumber != null)
            {
                var xacNhanDonHangs = db.XacNhanDonHangs.Include(k => k.KhachHang).Include(k => k.Voucher).Where(x => x.SDT.StartsWith(phoneNumber) || phoneNumber == null);
                return(View(xacNhanDonHangs.ToList()));
            }

            if (startDay != null & endDay != null)
            {
                DateTime startDateAsString = DateTime.Parse(startDay);
                DateTime endDateAsString   = DateTime.Parse(endDay);
                var      xacNhanDonHangs   = db.XacNhanDonHangs.Include(x => x.KhachHang).Include(x => x.Voucher).ToList()
                                             .Where(s => s.NgayXacNhan.CompareTo(startDateAsString) >= 0 & s.NgayXacNhan.CompareTo(endDateAsString) <= 0);
                return(View(xacNhanDonHangs));
            }
            else if (startDay != null & endDay == null)
            {
                DateTime startDateAsString = DateTime.Parse(startDay);
                var      xacNhanDonHangs   = db.XacNhanDonHangs.Include(x => x.KhachHang).Include(x => x.Voucher)
                                             .Where(s => s.NgayXacNhan.CompareTo(startDateAsString) >= 0 & s.NgayXacNhan.CompareTo(DateTime.Now.ToString()) <= 0);
                return(View(xacNhanDonHangs));
            }
            else
            {
                var xacNhanDonHangs = db.XacNhanDonHangs.Include(x => x.KhachHang).Include(x => x.Voucher);
                return(View(xacNhanDonHangs));
            }
        }