public IActionResult Index(string danhsach)
        {
            //if (String.IsNullOrEmpty(danhsach))
            //{
            //    TempData["status"] = "Không có sản phẩm nào được chọn";
            //    return RedirectToAction("Index", "HangHoa");
            //}
            List <GioHang> danhsachhang = JsonConvert.DeserializeObject <List <GioHang> >(danhsach);

            if (danhsachhang.Count() == 0)
            {
                TempData["status"] = "Không có sản phẩm nào được chọn";
                return(RedirectToAction("Index", "HangHoa"));
            }
            if (HttpContext.Session.GetString("User") == null || HttpContext.Session.GetString("User") == "")
            {
                TempData["status"] = "Bạn Cần Phải Đăng Nhập";
                return(RedirectToAction("Index", "HangHoa"));
            }
            GioHangViewModel list = new GioHangViewModel {
                GioHang = danhsachhang
            };

            ViewData["ClientId"] = _payPalOption.PayPalClientID ?? "";
            ViewBag.ClientId     = _payPalOption.PayPalClientID;
            return(View(list));
        }
示例#2
0
        public IActionResult Index()
        {
            GioHangViewModel query = new GioHangViewModel(db);

            ViewBag.ListOrder = query.GetDsGioHang().OrderByDescending(x => x.NgayDat);
            return(View());
        }
示例#3
0
        // GET: GioHang
        public ActionResult Index()
        {
            ViewBag.Title = "Giỏ hàng";
            GioHangViewModel model = new GioHangViewModel();

            model.GioHang = (GioHang)Session["Cart"];
            return(View(model));
        }
示例#4
0
 public GioHangController(ApplicationDbContext db)
 {
     _db       = db;
     GioHangVM = new GioHangViewModel()
     {
         SanPhams = new List <Models.SanPham>()
     };
 }
示例#5
0
 public CaNhanController(MobileContext db)
 {
     _db       = db;
     GioHangVM = new GioHangViewModel()
     {
         DanhSachGH   = new List <GioHang>(),
         DanhSachPost = new List <DanhSachPost>()
     };
 }
示例#6
0
        public IActionResult ChangeProgress(int id, int status)
        {
            GioHang gh = db.GioHang.SingleOrDefault(x => x.MaGioHang == id);

            gh.TrangThai = status;
            GioHangViewModel query = new GioHangViewModel(db);

            query.EditGioHang(gh);
            return(Json(true));
        }
示例#7
0
        public IActionResult RemoveOrder(string id)
        {
            ChiTietGioHangViewModel query_ctdh = new ChiTietGioHangViewModel(db);

            query_ctdh.DeleteChiTietGioHangByCartId(id);
            GioHangViewModel query_dh = new GioHangViewModel(db);

            query_dh.DeleteGioHangById(id);
            return(RedirectToAction("Index"));
        }
示例#8
0
        public IActionResult CancelOrder(string id)
        {
            GioHang gh = db.GioHang.Single(x => x.MaGioHang == int.Parse(id));

            gh.TrangThai = -1;
            GioHangViewModel query = new GioHangViewModel(db);

            query.EditGioHang(gh);
            return(RedirectToAction("Index"));
        }
        public ActionResult Payment()
        {
            ViewBag.Title = "Giỏ hàng";
            GioHangViewModel model = new GioHangViewModel();

            model.Cart = (Cart)Session["Cart"];
            F_Category fctg = new F_Category();

            ViewBag.ListCategory = fctg.getAll();
            return(View(model));
        }
        public IActionResult DatHang()
        {
            var items = _gioHang.LayChiTietGioHang();

            _gioHang.ChiTietGioHang = items;

            var x = new GioHangViewModel
            {
                GioHang         = _gioHang,
                TongTienGioHang = _gioHang.TinhTongTienGioHang()
            };

            return(View(x));
        }
示例#11
0
        public Task <IViewComponentResult> InvokeAsync()
        {
            List <GioHang> list = GetGioHangAsync();

            if (list == null)
            {
                list = new List <GioHang>();
            }
            GioHangViewModel giohang = new GioHangViewModel()
            {
                GioHang = list
            };

            return(Task.FromResult <IViewComponentResult>(View(giohang)));
        }
        public IActionResult Index()
        {
            ViewBag.EmployeeCount = (from nv in db.NhanVien select nv).Count();
            var listEarning                = new List <EarningMonth>();
            GioHangViewModel  query_gh     = new GioHangViewModel(db);
            NhanVienViewModel query_nv     = new NhanVienViewModel(db);
            double?           totalEarning = 0.0;
            int?totalItems  = 0;
            int totalOrders = 0;

            string[] monthNames = { "January", "February", "March",     "April",   "May",      "June",
                                    "July",    "August",   "September", "October", "November", "December" };
            for (int i = 1; i <= 12; i++)
            {
                listEarning.Add(new EarningMonth
                {
                    Month         = monthNames[i - 1],
                    Earning       = Math.Round(query_gh.GetEarningByMonth(i).GetValueOrDefault(), 0),
                    EmployeeCount = query_nv.GetCountEmployeeByMonth(i),
                    ItemCount     = query_gh.GetItemCountByMonth(i),
                    OrderCount    = query_gh.GetOrderCountByMonth(i)
                });
                totalEarning += query_gh.GetEarningByMonth(i);
                totalItems   += query_gh.GetItemCountByMonth(i);
                totalOrders  += query_gh.GetOrderCountByMonth(i);
            }
            var query_cv    = new ChucVuViewModel(db);
            var listCv      = query_cv.GetChucVu();
            var listPercent = new List <PositionPercent>();

            foreach (var cv in listCv)
            {
                listPercent.Add(new PositionPercent {
                    PositionName = cv.TenChucVu,
                    Percent      = Convert.ToInt32(query_nv.GetPercentEmployeePosition(cv.MaChucVu))
                });
            }
            ViewBag.TotalEarning = totalEarning;
            ViewBag.TotalItems   = totalItems;
            ViewBag.TotalOrders  = totalOrders;
            ViewBag.PositionName = JsonConvert.SerializeObject(listPercent.Select(x => x.PositionName));
            ViewBag.Percent      = JsonConvert.SerializeObject(listPercent.Select(x => x.Percent));
            return(View(listEarning));
        }
        //public ActionResult Home_Cart()
        //{
        //    var cart = Session[CommonConstants.CartSession];
        //    var list = new List<GioHangViewModel>();
        //    if (cart != null)
        //    {
        //        list = (List<GioHangViewModel>)cart;
        //    }
        //    return View(list);
        //}

        public ActionResult AddItem(int productid, int quantity)
        {
            var product = new ProductDAO().ViewProductDetail(productid);
            var cart    = Session[CommonConstants.CartSession];

            if (cart != null)
            {
                var list = (List <GioHangViewModel>)cart;
                if (list.Exists(x => x.Product.ID == productid))
                {
                    foreach (var item in list)
                    {
                        if (item.Product.ID == productid)
                        {
                            item.Quantity += quantity;
                        }
                    }
                }
                else
                {
                    // Tạo mới đối tượng cart item
                    var item = new GioHangViewModel();
                    item.Product  = product;
                    item.Quantity = quantity;
                    list.Add(item);
                }
                // Gán vào session
                Session[CommonConstants.CartSession] = list;
            }
            else
            {
                // Tạo mới đối tượng cart item
                var item = new GioHangViewModel();
                item.Product  = product;
                item.Quantity = quantity;

                var list = new List <GioHangViewModel>();
                list.Add(item);
                // Gán  vào session
                Session[CommonConstants.CartSession] = list;
            }

            return(RedirectToAction("Index"));
        }
示例#14
0
        public ActionResult ThanhToan(HoaDon hoadon)
        {
            GioHangViewModel model = new GioHangViewModel();

            model.GioHang = (GioHang)Session["Cart"];
            decimal tong = model.GioHang.ListItem.Sum(item => item.Gia * item.SoLuong);
            HoaDon  hd   = new HoaDon();

            hd.HovaTen          = hoadon.HovaTen;
            hd.DiaChi           = hoadon.DiaChi;
            hd.Email            = hoadon.Email;
            hd.Phone            = hoadon.Phone;
            hd.DiaChiGiaoHang   = hoadon.DiaChiGiaoHang;
            hd.ThoiGianGiaoHang = hoadon.ThoiGianGiaoHang;
            hd.NgayTao          = DateTime.Now;
            hd.TongTien         = tong;
            hd.TrangThai        = false;
            shop.HoaDon.Add(hd);
            shop.SaveChanges();

            var hoaDon = (from h in shop.HoaDon orderby h.MaHoaDon descending select h).FirstOrDefault();

            foreach (var item in model.GioHang.ListItem)
            {
                ChiTietHoaDon ct = new ChiTietHoaDon();
                ct.ChiTietHoaDon1 = shop.ChiTietHoaDon.Count() + 1;
                ct.MaHoaDon       = hoaDon.MaHoaDon;
                ct.MaSP           = item.MaSP;
                ct.SoLuong        = item.SoLuong;
                ct.TongTien       = item.SoLuong * shop.SanPham.Find(item.MaSP).GiaBan;
                shop.ChiTietHoaDon.Add(ct);
                shop.SaveChanges();
                CapNhatSLSanPham(item.MaSP, item.SoLuong);
            }
            model.GioHang.ListItem.Clear();
            return(View());
        }