public ActionResult Create(EventCreateViewModel model) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(model.Other)) model.EventItem.Event = model.Other; var user = db.Users.Find(User.Identity.GetUserId()); user.EventsList.Add(model.EventItem); db.SaveChanges(); return RedirectToAction("Index"); } return View(model); }
// GET: /Events/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return RedirectToAction("Index", "Events");//new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Events events = db.Events.Find(id); if (events == null) { return RedirectToAction("Index", "Events");//HttpNotFound(); } var model = new EventCreateViewModel(); model.EventItem = events; if (model.Subjects.Find(x => x.Text.Equals(model.EventItem.Event)) == null) { model.Other = model.EventItem.Event; model.EventItem.Event = "אחר"; } return View(model); }
// GET: /Events/Create public ActionResult Create() { var model = new EventCreateViewModel(); return View(model); }
public ActionResult Edit(EventCreateViewModel model) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(model.Other)) model.EventItem.Event = model.Other; db.Entry(model.EventItem).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(model); }