// GET: TransportPosts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TransportPost transportPost = db.TransportPosts.Find(id); if (transportPost == null) { return(HttpNotFound()); } UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId()); List <Transport> transportList = db.Transports.Where(c => c.User.Id == currentUser.Id).ToList(); if (currentUser == transportPost.User) { ViewBag.TransportID = new SelectList(transportList, "TransportID", "OrganizationName", transportPost.TransportID); return(View(transportPost)); } else { return(RedirectToAction("Index")); } //return View(transportPost); }
// GET: TransportPosts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TransportPost transportPost = db.TransportPosts.Find(id); if (transportPost == null) { return(HttpNotFound()); } UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId()); if (currentUser == transportPost.User) { return(View(transportPost)); } else { return(RedirectToAction("Index")); } //return View(transportPost); }
public ActionResult DeleteConfirmed(int id) { TransportPost transportPost = db.TransportPosts.Find(id); db.TransportPosts.Remove(transportPost); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "TransportPostID,TransportID,TimeStamp,Message,StartTimeAvailable,EndTimeAvailable,Comments")] TransportPost transportPost) { if (ModelState.IsValid) { db.Entry(transportPost).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TransportID = new SelectList(db.Transports, "TransportID", "OrganizationName", transportPost.TransportID); return(View(transportPost)); }
// GET: TransportPosts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TransportPost transportPost = db.TransportPosts.Find(id); if (transportPost == null) { return(HttpNotFound()); } return(View(transportPost)); }
// GET: TransportPosts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TransportPost transportPost = db.TransportPosts.Find(id); if (transportPost == null) { return(HttpNotFound()); } ViewBag.TransportID = new SelectList(db.Transports, "TransportID", "OrganizationName", transportPost.TransportID); return(View(transportPost)); }
public ActionResult Create([Bind(Include = "TransportPostID,TransportID,TimeStamp,Message,StartTimeAvailable,EndTimeAvailable,Comments,User_Id")] TransportPost transportPost) { UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId()); transportPost.User = currentUser; if (ModelState.IsValid) { db.TransportPosts.Add(transportPost); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TransportID = new SelectList(db.Transports, "TransportID", "OrganizationName", transportPost.TransportID); return(View(transportPost)); }