public ActionResult Create(IdeaModel model) { if (ModelState.IsValid) { ProjectPlannerContext ctx = new ProjectPlannerContext(); User currentUser = ctx.Users.SingleOrDefault(u => u.Username.Equals(User.Identity.Name)); Idea idea = new Idea { Name = model.Name, BriefDescription = model.BriefDescription, Description = model.Description }; currentUser.Suggestions.Add(idea); ctx.SaveChanges(); return Json(idea.IdeaID); } return View(model); }
public ActionResult Register(CreateModel model) { if (ModelState.IsValid) { ProjectPlannerContext ctx = new ProjectPlannerContext(); User user = new User { Username = model.Username, PasswordHash = model.Password.GetHash(), Name = model.Name, Email = model.Email }; if (ctx.Users.SingleOrDefault(u => u.Username == model.Username) != null) { ViewBag.Error = "Username already exists!"; return View(model); } ctx.Users.Add(user); ctx.SaveChanges(); return LogOn(new LogOnModel { Username = model.Username, Password = model.Password, RemindMe = false }, Url.Action("Index", "Home")); } return null; }
public ActionResult Support(int ideaID) { ProjectPlannerContext ctx = new ProjectPlannerContext(); Idea idea = ctx.Users.Select(u => u.Suggestions).Single(l => l.Where(s => s.IdeaID == ideaID).Count() != 0).Single(s => s.IdeaID == ideaID); User approver = ctx.Users.Single(u => u.Username.Equals(User.Identity.Name)); if (idea.Approvers == null) idea.Approvers = new List<User>(); idea.Approvers.Add(approver); ctx.SaveChanges(); return View("Supported"); }
public ActionResult Remove(int ideaID) { if (ModelState.IsValid) { ProjectPlannerContext ctx = new ProjectPlannerContext(); User currentUser = ctx.Users.SingleOrDefault(u => u.Username.Equals(User.Identity.Name)); Idea idea = currentUser.Suggestions.SingleOrDefault(i => i.IdeaID == ideaID); currentUser.Suggestions.Remove(idea); ctx.SaveChanges(); return View(); } return View(); }