예제 #1
0
        public ActionResult Update(int idLoai)
        {
            if (Session["TaiKhoan"] != null)
            {
                var tk = Session["TaiKhoan"] as KhachHang;


                if (tk.LoaiTK == "Khách Hàng")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    LoaiDAO dao = new LoaiDAO();
                    var     nsx = dao.GetLoai(idLoai);
                    if (nsx == null)
                    {
                        ViewBag.Alert = "Không thể tìm thấy loại";
                    }
                    else
                    {
                        Session["UpdateLoai"] = nsx;
                    }
                    return(View("Index"));
                }
            }
            else
            {
                return(View("../DangNhap/Index"));
            }
        }
예제 #2
0
        public IActionResult Create(Loai lo)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (lo.MoTa == null)
            {
                lo.MoTa = "";
            }
            if (lo.Hinh == null)
            {
                lo.Hinh = "";
            }

            int result = LoaiDAO.AddLoai(lo);

            if (result == 0)//thất bại
            {
                return(View());
            }
            //chuyển tới màn hình Edit loại
            return(RedirectToAction("Edit", new { id = result }));
        }
예제 #3
0
        public IActionResult Edit(int id)
        {
            Loai lo = LoaiDAO.GetLoai(id);

            if (lo != null)
            {
                return(View(lo));
            }
            //nếu ko có thì trở về màn hình Index
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public IActionResult Delete(int id)
        {
            Loai loai   = LoaiDAO.GetLoai(id);
            bool result = false;

            if (loai != null)
            {
                result = LoaiDAO.DeleteLoai(id);
            }

            ViewBag.ThongBao = $"Xóa loại {id}-{loai.TenLoai} {(result ? "thành công" : "thất bại")}";

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public JsonResult LayLoaiSanPham(int DanhMucID)
        {
            var list = new LoaiDAO().layDanhSachLoaiTheoID(DanhMucID);

            var output = JsonConvert.SerializeObject(list, new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            var jsonResult = Json(new
            {
                data = output
            }, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;

            return(jsonResult);
        }
예제 #6
0
        public ActionResult Index(string tenloai)
        {
            if (Session["TaiKhoan"] != null)
            {
                var tk = Session["TaiKhoan"] as KhachHang;


                if (tk.LoaiTK == "Khách Hàng")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    LoaiDAO dao = new LoaiDAO();
                    if (Session["UpdateLoai"] == null)
                    {
                        if (dao.ThemLoai(tk.MaKH, tenloai) == false)
                        {
                            ViewBag.Err = "Tên loại đã tồn tại";
                        }
                        else
                        {
                            Session["ListLoai"] = dao.GetList();
                        }
                    }
                    else
                    {
                        var nsx = Session["UpdateLoai"] as Loai;
                        if (dao.UpdateLoai(tk.MaKH, nsx.MaLoai, tenloai) == false)
                        {
                            ViewBag.Err = "Tên loại đã tồn tại";
                        }
                        else
                        {
                            Session["UpdateLoai"] = null;
                            Session["ListLoai"]   = dao.GetList();
                        }
                    }
                    return(View("Index"));
                }
            }
            else
            {
                return(View("../DangNhap/Index"));
            }
        }
예제 #7
0
        public IActionResult Edit(int id, Loai lo)
        {
            if (id != lo.MaLoai)
            {
                return(View());
            }

            //dựa vào mã đi kiếm loại đang có trong database
            Loai loai = LoaiDAO.GetLoai(id);

            if (loai != null)
            {
                //thực hiện sửa và cập nhật
                loai.TenLoai = lo.TenLoai;
                loai.MoTa    = lo.MoTa;
                loai.Hinh    = lo.Hinh;
                LoaiDAO.UpdateLoai(loai);
            }
            return(RedirectToAction("Index"));
        }
예제 #8
0
        public ActionResult Delete(bool confirm, int idLoai)
        {
            if (Session["TaiKhoan"] != null)
            {
                var tk = Session["TaiKhoan"] as KhachHang;


                if (tk.LoaiTK == "Khách Hàng")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    if (confirm == true)
                    {
                        LoaiDAO dao = new LoaiDAO();
                        if (dao.DeleteLoai(idLoai, tk.MaKH) == false)
                        {
                            ViewBag.Alert = "Không thể xóa loại này";
                        }
                        else
                        {
                            if (Session["UpdateLoai"] != null)
                            {
                                var nsx = Session["UpdateLoai"] as Loai;
                                if (nsx.MaLoai == idLoai)
                                {
                                    Session["UpdateLoai"] = null;
                                }
                            }
                            Session["ListLoai"] = dao.GetList();
                        }
                    }
                    return(View("Index"));
                }
            }
            else
            {
                return(View("../DangNhap/Index"));
            }
        }
예제 #9
0
        public void setViewBagForSanPham()
        {
            LoaiDAO       l  = new LoaiDAO();
            ThuongHieuDAO th = new ThuongHieuDAO();
            MauDAO        m  = new MauDAO();
            KichCoDAO     kc = new KichCoDAO();
            DanhMucDAO    dm = new DanhMucDAO();

            ViewBag.listImage = ImageHelper.loadListImage();           //lay danh sach hinh anh

            ViewBag.MaLoai = l.getDanhSach();                          //lay tat cac cac loai ---giai quyet

            ViewBag.MaThuongHieu = th.getTatCaThuongHieu();            //lay thuong hieu

            ViewBag.DanhSachSanPham = spDAO.layDanhSachTatCaSanPham(); //lay tat ca sp

            ViewBag.Mau = m.getDanhSach();                             //lat tat ca mau

            ViewBag.KichCo = kc.getDanhSach();                         //lat tat ca mau

            ViewBag.DanhMuc = dm.getDanhMuc();                         // lấy tất cả danh mục
        }
예제 #10
0
        public ActionResult TimKiem(string tenloai)
        {
            if (Session["TaiKhoan"] != null)
            {
                var tk = Session["TaiKhoan"] as KhachHang;


                if (tk.LoaiTK == "Khách Hàng")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    LoaiDAO dao = new LoaiDAO();
                    Session["ListLoai"] = dao.Search(tenloai);
                    return(View("Index"));
                }
            }
            else
            {
                return(View("../DangNhap/Index"));
            }
        }
예제 #11
0
        // GET: Loai
        public ActionResult Index()
        {
            if (Session["TaiKhoan"] != null)
            {
                var tk = Session["TaiKhoan"] as KhachHang;


                if (tk.LoaiTK == "Khách Hàng")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    LoaiDAO dao = new LoaiDAO();
                    Session["ListLoai"] = dao.GetList();
                    return(View());
                }
            }
            else
            {
                return(View("../DangNhap/Index"));
            }
        }
예제 #12
0
 public IActionResult Index()
 {
     return(View(LoaiDAO.ToList()));
 }