public ActionResult Edit(int id, EventEditorFormViewModel eventViewModel) { var eventToEdit = eventRepository.GetById(id); if (eventToEdit == null) { this.AddNotification(string.Format("Cannot edit event #{0}", id), NotificationType.ERROR); return(RedirectToAction("My")); } if (eventViewModel != null && ModelState.IsValid) { eventViewModel.ToModel(eventToEdit); eventRepository.Update(eventToEdit); eventRepository.Save(); this.AddNotification("Event edited.", NotificationType.INFO); return(RedirectToAction("Details", new RouteValueDictionary( new { controller = "Event", action = "Details", id = eventToEdit.Id }))); } ViewBag.Title = "Edit Event"; ViewBag.SubmitButtonText = "Save"; return(View("_EditorForm", eventViewModel)); }
public ActionResult Create(EventEditorFormViewModel eventViewModel) { if (eventViewModel != null && ModelState.IsValid) { var newEvent = new Event() { AuthorId = UserId }; eventViewModel.ToModel(newEvent); eventRepository.Insert(newEvent); eventRepository.Save(); this.AddNotification("Event created.", NotificationType.SUCCESS); return(RedirectToAction("Details", new RouteValueDictionary( new { controller = "Event", action = "Details", id = newEvent.Id }))); } ViewBag.Title = "Create New Event"; ViewBag.SubmitButtonText = "Save"; return(View("_EditorForm")); }