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 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(int id) { ViewBag.Title = "Update Company"; using (var db = new MyDbDataContext()) { Hotel hotel = db.Hotels.FirstOrDefault(a => a.ID == id); if (hotel == null) { TempData["Messages"] = "Does not exist"; return(RedirectToAction("Index")); } var eHotel = new EHotel { Name = hotel.Name, Logo = hotel.Logo, Image = hotel.Image, Tel = hotel.Tel, Fax = hotel.Fax, Email = hotel.Email, Address = hotel.Address, Location = hotel.Location, CodeBooking = hotel.CodeBooking, Website = hotel.Website, Condition = hotel.Condition, Tripadvisor = hotel.Tripadvisor, FaceBook = hotel.Facebook, Instagram = hotel.Instagram, Twitter = hotel.Twitter, Youtube = hotel.Youtube, CopyRight = hotel.CopyRight, MetaTitle = hotel.MetaTitle, MetaDescription = hotel.MetaDescription, Hotline = hotel.Hotline }; return(View(eHotel)); } }