public ActionResult EditPlace([Bind(Include = "Name,Location,Area,Photos,CurrentStatus,VisitorsPerYear")] Place place) { if (Session["UserAdmin"] != null) { if (ModelState.IsValid) { db.Entry(place).State = EntityState.Modified; db.SaveChanges(); adminManagePlace data = new adminManagePlace(); data.Action = "Edit"; data.Admin = Session["UserAdmin"].ToString(); data.Place = place.Name; adminDb.adminManagePlace.Add(data); adminDb.SaveChanges(); return(RedirectToAction("IndexPlace")); } ViewBag.Area = new SelectList(db.Area, "AreaTravelling", "AreaTravelling", place.Area); return(View(place)); } else { return(RedirectToAction("Login", "AdminManage")); } }
public ActionResult CreatePlace([Bind(Include = "Name,Location,Area,Photos,CurrentStatus,VisitorsPerYear")] Place place) { 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); byte[] imageArray = System.IO.File.ReadAllBytes(path); place.Photos = imageArray; place.totalRatings = 0; place.Rating = 0; db.Place.Add(place); db.SaveChanges(); adminManagePlace data = new adminManagePlace(); data.Action = "Create"; data.Admin = Session["UserAdmin"].ToString(); data.Place = place.Name; adminDb.adminManagePlace.Add(data); adminDb.SaveChanges(); return(RedirectToAction("IndexPlace")); } ViewBag.Area = new SelectList(db.Area, "AreaTravelling", "AreaTravelling", place.Area); return(View(place)); } else { return(RedirectToAction("Login", "AdminManage")); } }