public JsonResult Delete(int id) { try { using (var db = new MyDbDataContext()) { Menu del = db.Menus.FirstOrDefault(c => c.ID == id); //kiểm tra xem thằng này có menu con không List <Menu> listMenu = db.Menus.Where(m => m.ParentID == del.ID).ToList(); if (del != null) { db.Menus.DeleteAllOnSubmit(listMenu); db.SubmitChanges(); db.Menus.DeleteOnSubmit(del); db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Successful" })); } return(Json(new { Result = "OK", Message = "Menu not exist" })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", ex.Message })); } }
public ActionResult UpdateConfig(PaymentConfigOnePay model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { PaymentConfigOnePay Config = db.PaymentConfigOnePays.FirstOrDefault(); if (Config == null) { Config = new PaymentConfigOnePay(); db.PaymentConfigOnePays.InsertOnSubmit(Config); db.SubmitChanges(); ViewBag.Messages = "Thêm Payment Config OnePay thành công"; return(RedirectToAction("GoogleAnalytics")); } Config.AccessCode = model.AccessCode; Config.Hashcode = model.Hashcode; Config.MerchantId = model.MerchantId; Config.WebSite = model.WebSite; db.SubmitChanges(); ViewBag.Messages = "Chỉnh sửa Payment Config OnePay thành công"; return(RedirectToAction("Config")); } catch (Exception exception) { ViewBag.Messages = "Lỗi: " + exception.Message; return(View()); } } return(View(model)); } }
public ActionResult Update(EService model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { Service service = db.Services.FirstOrDefault(b => b.ID == model.ID); if (service != null) { service.Title = model.Title; service.MenuID = model.MenuID; service.Alias = model.Alias; service.Image = model.Image; service.Description = model.Description; service.Content = model.Content; service.MetaTitle = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle; service.MetaDescription = string.IsNullOrEmpty(model.MetaDescription) ? model.Title : model.MetaDescription; service.Status = model.Status; service.Home = model.Home; db.SubmitChanges(); //xóa gallery cho phòng db.ServiceGalleries.DeleteAllOnSubmit( db.ServiceGalleries.Where(a => a.ServiceID == service.ID).ToList()); //Thêm hình ảnh cho phòng if (model.EGalleryITems != null) { foreach (EGalleryITem itemGallery in model.EGalleryITems) { var serviceGallery = new ServiceGallery { ImageLarge = itemGallery.Image, ImageSmall = ReturnSmallImage.GetImageSmall(itemGallery.Image), ServiceID = service.ID, }; db.ServiceGalleries.InsertOnSubmit(serviceGallery); } db.SubmitChanges(); } TempData["Messages"] = "Sửa dịch vụ thành công"; return(RedirectToAction("Index")); } } catch (Exception exception) { ViewBag.Messages = "Error: " + exception.Message; LoadData(); return(View(model)); } } LoadData(); return(View(model)); } }
public ActionResult Update(ERoom model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { Room room = db.Rooms.FirstOrDefault(b => b.ID == model.ID); if (room != null) { room.Title = model.Title; room.Alias = model.Alias; room.Image = model.Image; room.MaxPeople = model.MaxPeople; room.Price = model.Price; room.PriceNet = model.PriceNet; room.Description = model.Description; room.Content = model.Content; room.MetaTitle = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle; room.MetaDescription = string.IsNullOrEmpty(model.MetaDescription) ? model.Title : model.MetaDescription; room.Status = model.Status; room.Home = model.Home; db.SubmitChanges(); //xóa gallery cho phòng db.RoomGalleries.DeleteAllOnSubmit(db.RoomGalleries.Where(a => a.RoomId == room.ID).ToList()); //Thêm hình ảnh cho phòng if (model.EGalleryITems != null) { foreach (EGalleryITem itemGallery in model.EGalleryITems) { var roomGallery = new RoomGallery { ImageLarge = itemGallery.Image, ImageSmall = ReturnSmallImage.GetImageSmall(itemGallery.Image), RoomId = room.ID, }; db.RoomGalleries.InsertOnSubmit(roomGallery); } db.SubmitChanges(); } TempData["Messages"] = "Sửa phòng thành công"; return(RedirectToAction("Index")); } } catch (Exception exception) { ViewBag.Messages = "Error: " + exception.Message; return(View(model)); } } return(View(model)); } }
public ActionResult Create(ERoom model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { Room room = new Room { LanguageID = Request.Cookies["lang_client"].Value, HotelId = model.HotelId, Title = model.Title, Image = model.Image, MaxPeople = model.MaxPeople, Price = model.Price, Index = model.Index, Status = model.Status, PriceNet = model.PriceNet, Description = model.Description, Content = model.Content, }; db.Rooms.InsertOnSubmit(room); db.SubmitChanges(); //Thêm hình ảnh cho phòng if (model.EGalleryITems != null) { foreach (EGalleryITem itemGallery in model.EGalleryITems) { var roomGallery = new RoomGallery { ImageLarge = itemGallery.Image, ImageSmall = ReturnSmallImage.GetImageSmall(itemGallery.Image), RoomId = room.ID, }; db.RoomGalleries.InsertOnSubmit(roomGallery); } db.SubmitChanges(); } TempData["Messages"] = "Insert successfull."; return(RedirectToAction("Index")); } catch (Exception exception) { LoadData(); TempData["Messages"] = "Error: " + exception.Message; return(View()); } } LoadData(); return(View()); } }
public ActionResult Update(ERoom model) { //Kiểm tra xem alias thuộc hotel này đã tồn tại chưa var db = new MyDbDataContext(); if (ModelState.IsValid) { try { var room = db.Rooms.FirstOrDefault(b => b.ID == model.ID); if (room != null) { room.HotelId = model.HotelId; room.Title = model.Title; room.Image = model.Image; room.MaxPeople = model.MaxPeople; room.Price = model.Price; room.Index = model.Index; room.Status = model.Status; room.PriceNet = model.PriceNet; room.Description = model.Description; room.Content = model.Content; db.SubmitChanges(); //xóa gallery cho phòng db.RoomGalleries.DeleteAllOnSubmit(db.RoomGalleries.Where(a => a.RoomId == room.ID).ToList()); //Thêm hình ảnh cho phòng if (model.EGalleryITems != null) { foreach (EGalleryITem itemGallery in model.EGalleryITems) { var roomGallery = new RoomGallery { ImageLarge = itemGallery.Image, ImageSmall = ReturnSmallImage.GetImageSmall(itemGallery.Image), RoomId = room.ID, }; db.RoomGalleries.InsertOnSubmit(roomGallery); } db.SubmitChanges(); } TempData["Messages"] = "Update successful."; return(RedirectToAction("Index")); } } catch (Exception exception) { LoadData(); TempData["Messages"] = "Error: " + exception.Message; return(View()); } } LoadData(); return(View(model)); }
public JsonResult DeleteCabin(int id) { try { Cabin model = db.Cabins.FirstOrDefault(a => a.ID == id); db.Cabins.DeleteOnSubmit(model); db.SubmitChanges(); return(Json(new { success = true })); } catch { return(Json(new { success = false })); } }
public ActionResult Create(FormCollection frm) { if (ModelState.IsValid) { try { var model = new ProjectLibrary.Database.PromotionCodeCabin(); model.Code = frm["txtCode"]; string[] str = frm["txtNgayBatDau"].ToString().Split('/', '-'); int day = int.Parse(str[0]); int month = int.Parse(str[1]); int year = int.Parse(str[2]); model.NgayBatDau = new DateTime(year, month, day); str = frm["txtNgayKetThuc"].ToString().Split('/', '-'); day = int.Parse(str[0]); month = int.Parse(str[1]); year = int.Parse(str[2]); model.NgayKetThuc = new DateTime(year, month, day); model.IDCabin = int.Parse(frm["txtIDCabin"].ToString()); model.IDCruise = int.Parse(frm["txtIDCruise"].ToString()); model.SL = int.Parse(frm["txtSL"].ToString()); model.DaDung = int.Parse(frm["txtDaDung"].ToString()); model.MoTa = frm["txtMoTa"].ToString(); model.TrangThai = bool.Parse(frm["txtTrangThai"].ToString()); Session["TrungMa"] = ""; List <ProjectLibrary.Database.PromotionCodeCabin> del = db.PromotionCodeCabins.Where(c => c.Code == model.Code && c.IDCabin == model.IDCabin).ToList(); if (del.Count < 1) { db.PromotionCodeCabins.InsertOnSubmit(model); db.SubmitChanges(); Session["TrungMa"] = "Thêm Thành Công!"; return(RedirectToAction("Index")); } else { Session["TrungMa"] = "TrungMa"; return(RedirectToAction("AddPromotion")); } } catch (Exception ex) { return(Json(new { success = false, Message = ex.Message })); } } return(RedirectToAction("AddPromotion")); }
public JsonResult Delete(int id) { try { using (var db = new MyDbDataContext()) { Service del = db.Services.FirstOrDefault(c => c.ID == id); if (del != null) { //xóa hết hình ảnh của phòng này db.ServiceGalleries.DeleteAllOnSubmit( db.ServiceGalleries.Where(a => a.ServiceID == del.ID).ToList()); db.Services.DeleteOnSubmit(del); db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Xóa dịch vụ thành công" })); } return(Json(new { Result = "ERROR", Message = "dịch vụ không tồn tại" })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", ex.Message })); } }
public JsonResult Edit(EmailMarketing model) { //End check using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { var edit = db.EmailMarketings.FirstOrDefault(b => b.Id == model.Id); if (edit != null) { edit.Email = model.Email; //edit.Tel = model.Tel; edit.Note = model.Note; db.SubmitChanges(); string message = "Update successful"; return(Json(new { Result = "OK", Message = message })); } else { return(Json(new { Result = "ERROR", Message = "Video is not exist" })); } } catch (Exception exception) { return(Json(new { Result = "Error", Message = "Error: " + exception.Message })); } } return(Json(new { Result = " Error", Errors = ModelState.Errors(), Message = "Input data are not correct in form" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Create(EmailMarketing model) { //End check using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { var emailmarketing = new EmailMarketing { Email = model.Email, //Tel = model.Tel, Note = model.Note, }; db.EmailMarketings.InsertOnSubmit(emailmarketing); db.SubmitChanges(); string message = "Insert successful"; return(Json(new { Result = "OK", Message = message, Record = model })); } catch (Exception exception) { return(Json(new { Result = "Error", Message = "Error: " + exception.Message })); } } return(Json(new { Result = " Error", Errors = ModelState.Errors(), Message = "Input data are not correct in form" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Delete(int ID) { try { using (var db = new MyDbDataContext()) { var del = db.ListHotels.FirstOrDefault(c => c.ID == ID); if (del != null) { //xóa hết hình ảnh của phòng này db.HotelGalleries.DeleteAllOnSubmit(db.HotelGalleries.Where(a => a.HotelId == del.ID).ToList()); //Xoa het phong cua hotel db.Rooms.DeleteAllOnSubmit(db.Rooms.Where(a => a.HotelId == del.ID).ToList()); db.ListHotels.DeleteOnSubmit(del); db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Delete successful" })); } return(Json(new { Result = "ERROR", Message = "Hotel is not exist" })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult UpdateIndex() { int menuId; int.TryParse(Request.Params["ListMenu"], out menuId); if (menuId == 0) { TempData["Messages"] = "Please select a menu."; return(RedirectToAction("Index")); } using (var db = new MyDbDataContext()) { var records = db.ListHotels.Where(r => r.MenuID == menuId).ToList(); foreach (var record in records) { var itemHotel = Request.Params[string.Format("Sort[{0}].Index", record.ID)]; int index; int.TryParse(itemHotel, out index); record.Index = index; db.SubmitChanges(); } TempData["Messages"] = "Sort successfull"; return(RedirectToAction("Index")); } }
public ActionResult Update(ESendEmail model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { SendEmail sendEmail = db.SendEmails.FirstOrDefault(b => b.ID == model.ID); if (sendEmail != null) { sendEmail.Title = model.Title; sendEmail.Content = model.Content; sendEmail.Success = model.Success; sendEmail.Error = model.Error; db.SubmitChanges(); TempData["Messages"] = "Successful"; return(RedirectToAction("Index")); } } catch (Exception exception) { ViewBag.Messages = "Lỗi: " + exception.Message; return(View()); } } return(View(model)); } }
public JsonResult SaveEmail(string Name, string Content) { try { using (var db = new MyDbDataContext()) { var checkEmail = db.FeedBacks.FirstOrDefault(a => a.Name == Name && a.Content == Content); if (checkEmail != null) { return(Json(new { result = "Error", message = "Email is exist" })); } FeedBack marketing = new FeedBack { Name = Name, Content = Content, }; db.FeedBacks.InsertOnSubmit(marketing); db.SubmitChanges(); return(Json(new { result = "ok" })); } } catch (Exception) { return(Json(new { result = "Error", message = "Error!" })); } }
public JsonResult SaveEmail(string emailMarketing) { try { using (var db = new MyDbDataContext()) { var checkEmail = db.EmailMarketings.FirstOrDefault(a => a.Email == emailMarketing); if (checkEmail != null) { return(Json(new { result = "Error", message = "Email is exist" })); } EmailMarketing marketing = new EmailMarketing { Email = emailMarketing, Tel = "", Note = "", }; db.EmailMarketings.InsertOnSubmit(marketing); db.SubmitChanges(); return(Json(new { result = "ok" })); } } catch (Exception) { return(Json(new { result = "Error", message = "Error!" })); } }
public ActionResult UpdateIndex(int locationID) { SystemMenuLocation localtionMenu = GetLocaltion(locationID); try { using (var db = new MyDbDataContext()) { List <Menu> menus = db.Menus.Where(c => c.LanguageID == Request.Cookies["lang_client"].Value).ToList(); foreach (Menu item in menus) { string requestIndex = Request.Params[string.Format("Sort[{0}].Index", item.ID)]; int index; int.TryParse(requestIndex, out index); Menu temp = db.Menus.FirstOrDefault(c => c.ID == item.ID); if (temp != null) { temp.Index = index; db.SubmitChanges(); } } } TempData["Messages"] = "successful"; return(RedirectToAction(localtionMenu.AliasMenu, "Menu")); } catch (Exception ex) { TempData["Messages"] = "Error: " + ex.Message; return(RedirectToAction(localtionMenu.AliasMenu, "Menu")); } }
public JsonResult Create(FeedBack model) { //End check using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { var FeedBack = new FeedBack { Name = model.Name, Content = model.Content, }; db.FeedBacks.InsertOnSubmit(FeedBack); db.SubmitChanges(); string message = "Insert successful"; return(Json(new { Result = "OK", Message = message, Record = model })); } catch (Exception exception) { return(Json(new { Result = "Error", Message = "Error: " + exception.Message })); } } return(Json(new { Result = " Error", Errors = ModelState.Errors(), Message = "Input data are not correct in form" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult SubmitContact(Contact model) { model.CreateDate = DateTime.Now; using (var db = new MyDbDataContext()) { model.CreateDate = DateTime.Now; db.Contacts.InsertOnSubmit(model); db.SubmitChanges(); SendEmail sendEmail = db.SendEmails.FirstOrDefault( a => a.Type == TypeSendEmail.Contact); Hotel hotel = CommentController.DetailHotel(Request.Cookies["LanguageID"].Value); sendEmail.Title = sendEmail.Title.Replace("{NameHotel}", hotel.Name); string content = sendEmail.Content; content = content.Replace("{FullName}", model.FullName); content = content.Replace("{Tel}", model.Tel); content = content.Replace("{Email}", model.Email); content = content.Replace("{Request}", model.Request); content = content.Replace("{NameHotel}", hotel.Name); content = content.Replace("{TelHotel}", hotel.Tel); content = content.Replace("{EmailHotel}", hotel.Email); content = content.Replace("{AddressHotel}", hotel.Address); content = content.Replace("{Website}", hotel.Website); MailHelper.SendMail(model.Email, sendEmail.Title, content); MailHelper.SendMail("*****@*****.**", hotel.Name + " Contact of " + model.FullName, content); return(Redirect("/Contact/Messages?status=success")); } }
public JsonResult Create(EConfigEmail model) { using (var db = new MyDbDataContext()) { if (db.ConfigWebsites.Any()) { return(Json(new { Result = "ERROR", Message = "Website chỉ được phép tồn tại 1 bản cấu hình" })); } if (ModelState.IsValid) { try { ConfigWebsite configWebsite = new ConfigWebsite { Host = model.Host, Port = model.Port, Email = model.Email, Password = CryptorEngine.Encrypt(model.Password, true), }; db.ConfigWebsites.InsertOnSubmit(configWebsite); db.SubmitChanges(); model.ID = configWebsite.ID; return(Json(new { Result = "OK", Message = "Thêm thành công", Record = model })); } catch (Exception exception) { return(Json(new { Result = "ERROR", Message = "Fail. Error:" + exception.Message })); } } return(Json(new { Result = "ERROR", Errors = ModelState.Errors(), Message = "Dữ liệu đầu vào không đúng định dạng" })); } }
public JsonResult Edit(EConfigEmail model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { var edit = db.ConfigWebsites.FirstOrDefault(b => b.ID == model.ID); if (edit != null) { edit.Port = model.Port; edit.Email = model.Email; edit.Password = CryptorEngine.Encrypt(model.Password, true); edit.Host = model.Host; db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Sửa thành công", Record = model })); } else { return(Json(new { Result = "ERROR", Message = "Bản ghi không tồn tại" })); } } catch (Exception exception) { return(Json(new { Result = "ERROR", Message = "Fail. Error:" + exception.Message })); } } return(Json(new { Result = "ERROR", Errors = ModelState.Errors(), Message = "Dữ liệu đầu vào không đúng định dạng" })); } }
public JsonResult Delete(int id) { try { using (var db = new MyDbDataContext()) { Tour del = db.Tours.FirstOrDefault(c => c.ID == id); if (del != null) { //xóa hết hình ảnh của tour này db.TourGalleries.DeleteAllOnSubmit(db.TourGalleries.Where(a => a.TourID == del.ID).ToList()); //xóa hết tabtour của tour này db.TabTours.DeleteAllOnSubmit(db.TabTours.Where(a => a.TourID == del.ID).ToList()); db.TabHotels.DeleteAllOnSubmit(db.TabHotels.Where(a => a.TourID == del.ID).ToList()); db.ThemesMenus.DeleteAllOnSubmit(db.ThemesMenus.Where(a => a.TourID == del.ID).ToList()); db.Tours.DeleteOnSubmit(del); db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Successful" })); } return(Json(new { Result = "ERROR", Message = "Tour not exist" })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", ex.Message })); } }
public JsonResult CheckMa(string code, int IDCabin) { try { using (var db = new MyDbDataContext()) { DateTime today = DateTime.Now; ProjectLibrary.Database.PromotionCodeCabin del = db.PromotionCodeCabins.FirstOrDefault(c => c.Code == code && c.IDCabin == IDCabin && today <= c.NgayKetThuc && today >= c.NgayBatDau && c.TrangThai == true); if (del != null) { /* * 1-het ma * 2-ok co ma va con luot dung * 3-loi ko co ma nao */ if (del.DaDung >= del.SL) { return(Json(new { Result = "OK", Message = "1" })); } else { del.DaDung = del.DaDung + 1; db.SubmitChanges(); return(Json(new { Result = "OK", Message = "2" })); } } return(Json(new { Result = "ERROR", Message = "3" })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", ex.Message })); } }
public ActionResult Create(EHotel model) { using (var db = new MyDbDataContext()) { if (db.Hotels.Any(a => a.LanguageID == Request.Cookies["lang_client"].Value)) { TempData["Messages"] = "Website is exist"; return(RedirectToAction("Index")); } if (ModelState.IsValid) { try { var hotel = new Hotel { LanguageID = Request.Cookies["lang_client"].Value, Name = model.Name, Logo = model.Logo, Image = model.Image, Tel = model.Tel, Fax = model.Fax, Email = model.Email, Address = model.Address, Location = model.Location, CodeBooking = model.CodeBooking, Website = model.Website, Condition = model.Condition, Tripadvisor = model.Tripadvisor, Facebook = model.FaceBook, Instagram = model.Instagram, Twitter = model.Twitter, Youtube = model.Youtube, CopyRight = model.CopyRight, Hotline = model.Hotline, MetaTitle = string.IsNullOrEmpty(model.MetaTitle) ? model.Name : model.MetaTitle, MetaDescription = string.IsNullOrEmpty(model.MetaDescription) ? model.Name : model.MetaDescription }; db.Hotels.InsertOnSubmit(hotel); db.SubmitChanges(); TempData["Messages"] = "Successful"; return(RedirectToAction("Index")); } catch (Exception exception) { ViewBag.Messages = "Error: " + exception.Message; return(View()); } } return(View()); } }
public ActionResult Create(EUser model) { using (var db = new MyDbDataContext()) { User checkUserName = db.Users.FirstOrDefault(a => a.UserName == model.UserName); if (checkUserName != null) { ModelState.AddModelError("UserName", "Username is exist"); } User checkEmail = db.Users.FirstOrDefault(a => a.Email == model.Email); if (checkEmail != null) { ModelState.AddModelError("Email", "Email is exist"); } if (ModelState.IsValid) { try { var insert = new User { UserName = model.UserName, Password = Password.HashPassword(model.Password), FullName = model.FullName, Email = model.Email, PasswordOld = model.Password, //PasswordOld = CryptorEngine.Encrypt(model.Password, true), Status = model.Status, UserContent = model.UserContent, }; db.Users.InsertOnSubmit(insert); db.SubmitChanges(); model.ID = insert.ID; return(Json(new { Result = "OK", Message = "Successful", Record = model })); } catch (Exception exception) { return(Json(new { Result = "Error", Message = "Error: " + exception.Message })); } } return (Json( new { Result = "Error", Errors = ModelState.Errors(), Message = "error data" })); } }
public JsonResult Delete(int Id) { var db = new MyDbDataContext(); BookRoom del = db.BookRooms.FirstOrDefault(a => a.ID == Id); if (del == null) { return(Json(new { Result = "ERROR", Message = "Đặt phòng không tồn tại." })); } db.BookRooms.DeleteOnSubmit(del); db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Xóa thành công." })); }
public JsonResult Delete(int id) { var db = new MyDbDataContext(); Contact del = db.Contacts.FirstOrDefault(a => a.ID == id); if (del == null) { return(Json(new { Result = "ERROR", Message = "does not exist" })); } db.Contacts.DeleteOnSubmit(del); db.SubmitChanges(); return(Json(new { Result = "OK", Message = "Successful" })); }
public ActionResult Create(EArticle model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { if (string.IsNullOrEmpty(model.Alias)) { model.Alias = StringHelper.ConvertToAlias(model.Alias); } try { var article = new Article { MenuID = model.MenuID, Title = model.Title, Alias = model.Alias, Image = model.Image, Description = model.Description, Content = model.Content, Index = 0, MetaTitle = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle, MetaDescription = string.IsNullOrEmpty(model.MetaDescription) ? model.Title : model.Description, Status = model.Status, Home = model.Home, Hot = model.Hot, New = model.New, TripLao = model.TripLao, TripCambodia = (bool)model.TripCambodia, TripvietNam = (bool)model.TripVietNam }; db.Articles.InsertOnSubmit(article); db.SubmitChanges(); TempData["Messages"] = "Successful"; return(RedirectToAction("Index")); } catch (Exception exception) { LoadData(); ViewBag.Messages = "Error: " + exception.Message; return(View()); } } LoadData(); return(View()); } }
public ActionResult Update(EHotel model) { using (var db = new MyDbDataContext()) { if (ModelState.IsValid) { try { Hotel hotel = db.Hotels.FirstOrDefault(b => b.ID == model.ID); if (hotel != null) { hotel.Name = model.Name; hotel.Logo = model.Logo; hotel.Image = model.Image; hotel.Tel = model.Tel; hotel.Fax = model.Fax; hotel.Email = model.Email; hotel.Address = model.Address; hotel.Location = model.Location; hotel.CodeBooking = model.CodeBooking; hotel.Website = model.Website; hotel.Condition = model.Condition; hotel.Tripadvisor = model.Tripadvisor; hotel.Facebook = model.FaceBook; hotel.Instagram = model.Instagram; hotel.Twitter = model.Twitter; hotel.Youtube = model.Youtube; hotel.CopyRight = model.CopyRight; hotel.Hotline = model.Hotline; hotel.MetaTitle = string.IsNullOrEmpty(model.MetaTitle) ? model.Name : model.MetaTitle; hotel.MetaDescription = string.IsNullOrEmpty(model.MetaDescription) ? model.Name : model.MetaDescription; db.SubmitChanges(); TempData["Messages"] = "Successful"; return(RedirectToAction("Index")); } } catch (Exception exception) { ViewBag.Messages = "Error: " + exception.Message; return(View()); } } return(View(model)); } }
public ActionResult Update(EArticle model) { using (var db = new MyDbDataContext()) { if (string.IsNullOrEmpty(model.Alias)) { model.Alias = StringHelper.ConvertToAlias(model.Alias); } try { Article article = db.Articles.FirstOrDefault(b => b.ID == model.ID); if (article != null) { article.MenuID = model.MenuID; article.Title = model.Title; article.Alias = model.Alias; article.Image = model.Image; article.Description = model.Description; article.Content = model.Content; article.MetaTitle = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle; article.MetaDescription = string.IsNullOrEmpty(model.MetaDescription) ? model.Title : model.MetaDescription; article.Status = model.Status; article.Home = model.Home; article.Hot = model.Hot; article.New = model.New; article.TripLao = model.TripLao; article.TripvietNam = model.TripVietNam; article.TripCambodia = model.TripCambodia; db.SubmitChanges(); //db.SubmitChanges(); TempData["Messages"] = "Successful"; return(RedirectToAction("Index")); } } catch (Exception exception) { LoadData(); ViewBag.Messages = "Error: " + exception.Message; return(View()); } } LoadData(); return(View(model)); }