コード例 #1
0
 public ActionResult ThemMoiHoa(HOA hoa, HttpPostedFileBase fileUp)
 {
     if (Session["TKAD"] == null)
     {
         return(RedirectToAction("Login", "HomeAdmin"));
     }
     ViewBag.MACHUDE = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.TENCHUDE), "MACHUDE", "TENCHUDE");
     ViewBag.Loai    = new SelectList(db.LOAIs.ToList().OrderBy(n => n.TENLOAI), "MALOAI", "TENLOAI");
     if (fileUp == null)
     {
         ViewBag.ThongBao = "Vui lòng chọn ảnh bìa";
         return(View());
     }
     else
     {
         if (ModelState.IsValid)
         {
             var filename = Path.GetFileName(fileUp.FileName);
             var path     = Path.Combine(Server.MapPath("~/Hinh"), filename);
             if (System.IO.File.Exists(path))
             {
                 ViewBag.ThongBao = "Hình ảnh đã tồn tại";
             }
             else
             {
                 fileUp.SaveAs(path);
             }
             hoa.ANHBIA = filename;
             // Lưu vào cơ sở dữ liệu
             db.HOAs.InsertOnSubmit(hoa);
             db.SubmitChanges();
         }
         return(RedirectToAction("QLHoa", "HomeAdmin"));
     }
 }
コード例 #2
0
        public ActionResult Suasp(HOA sp, HttpPostedFileBase fileUpload)
        {
            HOA spm = db.HOAs.SingleOrDefault(n => n.Mahoa == sp.Mahoa);

            ViewBag.MaSanPham = sp.Mahoa;
            var Tenhoa     = sp.Tenhoa;
            var Matk       = sp.MaTK;
            var Macd       = sp.MaCD;
            var Mota       = sp.Mota;
            var Gia        = sp.Giaban;
            var Soluongton = sp.Soluongton;
            var Anh        = sp.Anhbia;
            var ngaycn     = sp.Ngaycapnhat;

            spm.Ngaycapnhat = ngaycn;
            spm.Tenhoa      = Tenhoa;
            spm.Anhbia      = Anh;
            spm.MaTK        = Matk;
            spm.MaCD        = Macd;
            spm.Mota        = Mota;
            spm.Giaban      = Gia;
            spm.Soluongton  = Soluongton;

            if (ModelState.IsValid)
            {
                ViewBag.MaTK = new SelectList(db.THIETKEs.ToList().OrderBy(n => n.KieuThietKe), "MaTK", "KieuThietKe");
                ViewBag.MaCD = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.TenChuDe), "MaCD", "TenChuDe");
                if (fileUpload == null)
                {
                    spm.Anhbia = getImage(sp.Mahoa);
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        var fileName = Path.GetFileName(fileUpload.FileName);
                        var path     = Path.Combine(Server.MapPath("~/images/"), fileName);
                        if (System.IO.File.Exists(path))
                        {
                            sp.Anhbia        = fileName;
                            ViewBag.Thongbao = "Hình ảnh đã tồn tại";
                            return(View(sp));
                        }
                        else
                        {
                            fileUpload.SaveAs(path);
                            spm.Anhbia = fileName;
                        }
                    }
                }
                db.SubmitChanges();
            }
            return(RedirectToAction("Hoa"));
        }
コード例 #3
0
        public ActionResult Xoahoa(int id)
        {
            //Lay ra doi tuong sach can xoa theo ma
            HOA hoa = db.HOAs.SingleOrDefault(n => n.Mahoa == id);

            ViewBag.Masach = hoa.Mahoa;
            if (hoa == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(hoa));
        }
コード例 #4
0
        public ActionResult Suasp(int id)
        {
            HOA sp = db.HOAs.SingleOrDefault(n => n.Mahoa == id);

            ViewBag.MaSanPham = sp.Mahoa;
            if (sp == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            ViewBag.MaTK = new SelectList(db.THIETKEs.ToList().OrderBy(n => n.KieuThietKe), "MaTK", "KieuThietKe", sp.MaTK);
            ViewBag.MaCD = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.TenChuDe), "MaCD", "TenChuDe", sp.MaCD);
            return(View(sp));
        }
コード例 #5
0
        public ActionResult Xacnhanxoa(int id)
        {
            //Lay ra doi tuong sach can xoa theo ma
            HOA hoa = db.HOAs.SingleOrDefault(n => n.Mahoa == id);

            ViewBag.Mahoa = hoa.Mahoa;
            if (hoa == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.HOAs.DeleteOnSubmit(hoa);
            db.SubmitChanges();
            return(RedirectToAction("Hoa"));
        }
コード例 #6
0
        public ActionResult XoaHoa(int id)
        {
            if (Session["TKAD"] == null)
            {
                return(RedirectToAction("Login", "HomeAdmin"));
            }
            HOA hoa = db.HOAs.SingleOrDefault(n => n.MAHOA == id);

            ViewBag.MAHOA = hoa.MAHOA;
            if (hoa == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(hoa));
        }
コード例 #7
0
        public ActionResult CapNhatHoa(int id)
        {
            if (Session["TKAD"] == null)
            {
                return(RedirectToAction("Login", "HomeAdmin"));
            }
            HOA hoa = db.HOAs.SingleOrDefault(n => n.MAHOA == id);

            if (hoa == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            ViewBag.MACHUDE = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.TENCHUDE), "MACHUDE", "TENCHUDE", hoa.MAHOA);
            ViewBag.Loai    = new SelectList(db.LOAIs.ToList().OrderBy(n => n.TENLOAI), "MALOAI", "TENLOAI", hoa.LOAI);
            return(View(hoa));
        }
コード例 #8
0
        public ActionResult XacNhanXoaHoa(int id)
        {
            if (Session["TKAD"] == null)
            {
                return(RedirectToAction("Login", "HomeAdmin"));
            }
            HOA hoa = db.HOAs.SingleOrDefault(n => n.MAHOA == id);

            ViewBag.MAHOA = hoa.MAHOA;
            if (hoa == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.HOAs.DeleteOnSubmit(hoa);
            db.SubmitChanges();
            return(RedirectToAction("QLHoa"));
        }
コード例 #9
0
 public ActionResult Themmoihoa(HOA hoa, HttpPostedFileBase fileUpload)
 {
     //Dua du lieu vao dropdownload
     ViewBag.MaCD = new SelectList(db.CHUDEs.ToList().OrderBy(n => n.TenChuDe), "MaCD", "TenChuDe");
     ViewBag.MaTK = new SelectList(db.THIETKEs.ToList().OrderBy(n => n.KieuThietKe), "MaTK", "KieuThietKe");
     //Kiem tra duong dan file
     if (fileUpload == null)
     {
         ViewBag.Thongbao = "Vui lòng chọn ảnh bìa";
         return(View());
     }
     //Them vao CSDL
     else
     {
         if (ModelState.IsValid)
         {
             //Luu ten fie, luu y bo sung thu vien using System.IO;
             var fileName = Path.GetFileName(fileUpload.FileName);
             //Luu duong dan cua file
             var path = Path.Combine(Server.MapPath("~/images"), fileName);
             //Kiem tra hình anh ton tai chua?
             if (System.IO.File.Exists(path))
             {
                 ViewBag.Thongbao = "Hình ảnh đã tồn tại";
             }
             else
             {
                 //Luu hinh anh vao duong dan
                 fileUpload.SaveAs(path);
             }
             hoa.Anhbia = fileName;
             //Luu vao CSDL
             db.HOAs.InsertOnSubmit(hoa);
             db.SubmitChanges();
             return(RedirectToAction("Hoa"));
         }
         return(View());
     }
 }