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 ContentResult Register(int id) { Together together = TogetherRepository.GetTogether(id); if (!together.IsUserRegistered(User.Identity.Name)) { Attendee attendee = new Attendee(); attendee.AttendeeBy = User.Identity.Name; attendee.UserName = User.Identity.UserName(); attendee.TinyURL = User.Identity.TinyURL(); together.Attendees.Add(attendee); TogetherRepository.Save(); } return(Content("лл£¬²»¼û²»É¢Å¶£¡")); }
public ActionResult Delete(int id, string confirmButton) { Together together = TogetherRepository.GetTogether(id); if (!together.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } if (together == null) { return(View("NotFound")); } TogetherRepository.Delete(together); TogetherRepository.Save(); return(View("Deleted")); }
public ActionResult Details(Post post) { if (ModelState.IsValid) { try { post.PostDate = DateTime.Now; post.PostBy = User.Identity.Name; post.UserName = User.Identity.UserName(); post.TinyURL = User.Identity.TinyURL(); TogetherRepository.AddPost(post); TogetherRepository.Save(); return(RedirectToAction("Details", new { id = post.TogetherID })); } catch { ModelState.AddRuleViolations(post.GetRuleViolations()); } } ViewData["PostForm"] = post; return(View(post.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))); } }