public ActionResult Create(Together together) { if (ModelState.IsValid) { try { together.HostedBy = User.Identity.Name; together.TinyURL = User.Identity.TinyURL(); together.UserName = User.Identity.UserName(); Attendee attendee = new Attendee(); attendee.AttendeeBy = User.Identity.Name; attendee.UserName = User.Identity.UserName(); attendee.TinyURL = User.Identity.TinyURL(); together.Attendees.Add(attendee); TogetherRepository.Add(together); TogetherRepository.Save(); return(RedirectToAction("Details", new { id = together.TogetherID })); } catch { ModelState.AddRuleViolations(together.GetRuleViolations()); return(View(new TogetherFormViewModel(together))); } } return(View(new TogetherFormViewModel(together))); }
public ActionResult Edit(int id, FormCollection formValues) { Together together = TogetherRepository.GetTogether(id); if (!together.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } try { UpdateModel(together); TogetherRepository.Save(); return(RedirectToAction("Details", new { id = together.TogetherID })); } catch { ModelState.AddRuleViolations(together.GetRuleViolations()); return(View(new TogetherFormViewModel(together))); } }