Esempio n. 1
0
        public ActionResult ChinhSua(int id)
        {
            SanPham sp = _spService.LayTheoMa(id);

            if (sp == null)
            {
                return(HttpNotFound());
            }

            ViewBag.MaNCC = new SelectList(_nccService.LayTatCa(), "MaNCC", "Ten");
            ViewBag.MaLSP = new SelectList(_lspService.LayTatCa(), "MaLSP", "Ten");
            ViewBag.MaNSX = new SelectList(_nsxService.LayTatCa(), "MaNSX", "Ten");
            return(View(sp));
        }
        public ActionResult NhapHang(PhieuNhap pn, IEnumerable <ChiTietPhieuNhap> ctpn)
        {
            ViewBag.MaNCC       = _nccService.LayTatCa();
            ViewBag.ListSanPham = _spService.LayTatCa();
            _pnService.ThemMoi(pn);
            _pnService.luu();
            foreach (var item in ctpn)
            {
                // update Số Lượng Tồn
                SanPham sp = _spService.LayTheoMa(item.MaSP);
                sp.SoLuongTon += item.SoLuongNhap;

                item.MaPN = pn.MaPN;
                _ctpnService.ThemMoi(item);
            }
            _ctpnService.luu();
            ViewBag.Message = "Nhập hàng thành công!";
            return(View());
        }
        public ActionResult ThemVaoGioHang(int MaSP, string strURL)
        {
            SanPham sp = _spService.LayTheoMa(MaSP);

            if (sp == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            List <VatPhamTrongGioHang> GioHang = LayGioHang();
            VatPhamTrongGioHang        spCheck = GioHang.SingleOrDefault(x => x.MaSP == MaSP);

            if (spCheck != null)
            {
                if (sp.SoLuongTon - spCheck.SoLuong < spCheck.SoLuong)
                {
                    return(View("ThongBao"));
                }
                spCheck.SoLuong++;
                spCheck.ThanhTien = spCheck.SoLuong * spCheck.DonGia;
                return(Redirect(strURL));
            }

            VatPhamTrongGioHang item = new VatPhamTrongGioHang();

            item.MaSP      = MaSP;
            item.TenSP     = sp.Ten;
            item.HinhAnh   = sp.HinhAnh;
            item.DonGia    = sp.DonGia;
            item.SoLuong   = 1;
            item.ThanhTien = item.DonGia * item.SoLuong;

            if (sp.SoLuongTon < item.SoLuong)
            {
                return(View("ThongBao"));
            }

            GioHang.Add(item);
            return(Redirect(strURL));
        }
Esempio n. 4
0
        public ActionResult XemChiTiet(int id = -1)
        {
            if (id <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SanPham sp = _spService.LayTheoMa(id);

            if (sp == null)
            {
                return(HttpNotFound());
            }
            int totalRow = 0;

            ViewBag.SanPhamCungLoai = _spService.LaySanPhamTheoDanhMuc(sp.MaLSP, -1, 1, 10, "", out totalRow);
            return(View(sp));
        }