public ActionResult Create(Event e) { if (e.Type == null || e.Date == DateTime.MinValue) { return RedirectToAction("Index"); } try { var newEvent = new Event { Type = e.Type, Date = e.Date}; var user = Db.Users.Find(User.Identity.GetUserId()); user.Events.Add(newEvent); Db.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, Event e) { if (e.Type == null || e.Date == DateTime.MinValue) { return RedirectToAction("Index"); } try { var EventId = Db.Events.FirstOrDefault(x => x.EventId == id); EventId.Date = e.Date; EventId.Type = e.Type; Db.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }