Exemple #1
0
        public ActionResult AddRooms()
        {
            if (Session["LoggedCNT"] == null || Session["LoggedCNT"].ToString() == "")
            {
                return(RedirectToAction("Index", "Home"));
            }
            phongtro pt = new phongtro();

            return(View("AddRooms", pt));
        }
Exemple #2
0
 public ActionResult DeleteRoom(int id)
 {
     try
     {
         phongtro pt = db.phongtros.SingleOrDefault(m => m.Maphongtro == id);
         db.phongtros.DeleteOnSubmit(pt);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         TempData["message"] = "fail";
     }
     TempData["message2"] = "delete";
     return(RedirectToAction("Room"));
 }
Exemple #3
0
        public ActionResult AddRooms(phongtro pt, HttpPostedFileBase fileupload)
        {
            if (Session["LoggedCNT"] == null || Session["LoggedCNT"].ToString() == "")
            {
                return(RedirectToAction("Index", "Home"));
            }
            //Kiem tra duong dan file
            try {
                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/phongtro/"), 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);
                        }
                        pt.Images = fileName;
                        //Luu vao CSDL

                        DateTime  date = DateTime.Now;
                        chunhatro cnt  = (chunhatro)Session["LoggedCNT"];
                        pt.Machunhatro = cnt.Machunhatro;
                        db.phongtros.InsertOnSubmit(pt);
                        db.SubmitChanges();
                    }
                }
                TempData["message"] = "success";
            }
            catch (Exception ex) { TempData["message"] = "fail"; }
            TempData["message2"] = "add";
            return(RedirectToAction("Room"));
        }
Exemple #4
0
 public ActionResult EditRoom(phongtro pt, HttpPostedFileBase fileupload)
 {
     if (Session["LoggedCNT"] == null || Session["LoggedCNT"].ToString() == "")
     {
         return(RedirectToAction("Index", "Home"));
     }
     try {
         phongtro  ptt = db.phongtros.SingleOrDefault(n => n.Maphongtro == pt.Maphongtro);
         chunhatro cnt = (chunhatro)Session["LoggedCNT"];
         ptt.Machunhatro    = cnt.Machunhatro;
         ptt.Googlemap      = "";
         ptt.Sophong        = pt.Sophong;
         ptt.Diachi         = pt.Diachi;
         ptt.Tiendatcoc     = pt.Tiendatcoc;
         ptt.Noiquyphongtro = pt.Noiquyphongtro;
         ptt.Mota           = pt.Mota;
         if (ModelState.IsValid)
         {
             if (fileupload == null)
             {
                 ptt.Images = db.phongtros.SingleOrDefault(n => n.Maphongtro == pt.Maphongtro).Images;
             }
             else
             {
                 if (ModelState.IsValid)
                 {
                     var fileName = Path.GetFileName(fileupload.FileName);
                     var path     = Path.Combine(Server.MapPath("~/images/phongtro"), fileName);
                     if (System.IO.File.Exists(path))
                     {
                         pt.Images        = fileName;
                         ViewBag.Thongbao = "Hình ảnh đã tồn tại";
                         return(View(pt));
                     }
                     else
                     {
                         fileupload.SaveAs(path);
                         ptt.Images = fileName;
                     }
                 }
             }
             db.SubmitChanges();
             TempData["message"] = "success";
         }
     } catch (Exception ex) { TempData["message"] = "fail"; }
     TempData["message2"] = "edit";
     return(RedirectToAction("Room"));
 }