public ActionResult EditHotel([Bind(Include = "Name,Address,PhoneNumber")] Hotel hotel) { if (Session["UserAdmin"] != null) { if (ModelState.IsValid) { db.Entry(hotel).State = EntityState.Modified; db.SaveChanges(); adminManageHotel data = new adminManageHotel(); data.Action = "Edit"; data.Admin = Session["UserAdmin"].ToString(); data.Hotel = hotel.Name; adminDb.adminManageHotel.Add(data); adminDb.SaveChanges(); return(RedirectToAction("IndexHotel")); } return(View(hotel)); } else { return(RedirectToAction("Login", "AdminManage")); } }
public ActionResult CreateHotel([Bind(Include = "Name,Place,Address,Photos,PhoneNumber,Price")] Hotel hotel) { if (Session["UserAdmin"] != null) { if (ModelState.IsValid) { HttpPostedFileBase file = Request.Files["imageData"]; string path = Path.Combine(Server.MapPath("~/Photos"), Path.GetFileName(file.FileName)); file.SaveAs(path); //add data to table hotel byte[] imageArray = System.IO.File.ReadAllBytes(path); hotel.Photos = imageArray; hotel.totalRatings = 0; hotel.Rating = 0; db.Hotel.Add(hotel); db.SaveChanges(); //add data to table admin hotel manage adminManageHotel data = new adminManageHotel(); data.Action = "Create"; data.Admin = Session["UserAdmin"].ToString(); data.Hotel = hotel.Name; adminDb.adminManageHotel.Add(data); adminDb.SaveChanges(); return(RedirectToAction("IndexHotel")); } return(View(hotel)); } else { return(RedirectToAction("Login", "AdminManage")); } }
public ActionResult DeleteHotelConfirmed(int id) { if (Session["UserAdmin"] != null) { Hotel hotel = db.Hotel.Where(x => x.ID == id).FirstOrDefault(); db.Hotel.Remove(hotel); db.SaveChanges(); adminManageHotel data = new adminManageHotel(); data.Action = "Delete"; data.Admin = Session["UserAdmin"].ToString(); data.Hotel = hotel.Name; adminDb.adminManageHotel.Add(data); adminDb.SaveChanges(); return(RedirectToAction("IndexHotel")); } else { return(RedirectToAction("Login", "AdminManage")); } }