public ActionResult AddCollaborator(CollaborateViewModel collaborate) { string searchedCollaborator = collaborate.InputCollaborator; try { ApplicationUser searchedUser = db.Users.First(x => x.UserName == searchedCollaborator); Tutorial tut = db.Tutorials.First(x => x.Title == collaborate.TutorialSelection); CollaborativeTutorial collaborativeTutorial = new CollaborativeTutorial() { Tutorial = tut, TutorialId = tut.ID, }; collaborativeTutorial.Collaborators.Add(searchedUser); searchedUser.Collaborations.Add(collaborativeTutorial); db.Entry(searchedUser).State = EntityState.Modified; db.CollaborativeTutorials.Add(collaborativeTutorial); db.SaveChanges(); return(RedirectToAction("Index")); } catch (InvalidOperationException) { return(View(collaborate)); } }
public ActionResult Collaborate(CollaborativeTutorial model) { CollaborativeTutorial collabTutorial = db.CollaborativeTutorials.Find(model.Id); Tutorial tut = db.Tutorials.First(x => x.ID == model.TutorialId); Comment comment = new Comment() { UserName = User.Identity.GetUserName(), Text = model.newComment, TimeStamp = DateTime.Now }; collabTutorial.Comments.Add(comment); //db.Entry(collabTut).State = System.Data.Entity.EntityState.Modified; collabTutorial.Comments = collabTutorial.Comments.OrderBy(x => x.TimeStamp).ToList(); db.SaveChanges(); return RedirectToAction("Collaborate"); }
public ActionResult Collaborate(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CollaborativeTutorial collabtutorial = db.CollaborativeTutorials.Find(id); Tutorial t = db.Tutorials.First(x => x.ID == collabtutorial.TutorialId); collabtutorial.Tutorial = t; collabtutorial.Comments = collabtutorial.Comments.OrderBy(x => x.TimeStamp).ToList(); if (collabtutorial == null) { return(HttpNotFound()); } return(View(collabtutorial)); }
public ActionResult Collaborate(CollaborativeTutorial model) { CollaborativeTutorial collabTutorial = db.CollaborativeTutorials.Find(model.Id); Tutorial tut = db.Tutorials.First(x => x.ID == model.TutorialId); Comment comment = new Comment() { UserName = User.Identity.GetUserName(), Text = model.newComment, TimeStamp = DateTime.Now }; collabTutorial.Comments.Add(comment); //db.Entry(collabTut).State = System.Data.Entity.EntityState.Modified; collabTutorial.Comments = collabTutorial.Comments.OrderBy(x => x.TimeStamp).ToList(); db.SaveChanges(); return(RedirectToAction("Collaborate")); }
private bool CanEdit(int?id) { var currentUser = db.Users.Find(User.Identity.GetUserId()); try { CollaborativeTutorial collab = currentUser.Collaborations.First(x => x.TutorialId == id); CollaborativeTutorial collabTut = db.CollaborativeTutorials.First(x => x.TutorialId == id); if (collabTut.Collaborators.Contains(currentUser) || collab != null) { return(true); } else { return(false); } } catch (InvalidOperationException) { return(false); } }
public ActionResult AddCollaborator(CollaborateViewModel collaborate) { string searchedCollaborator = collaborate.InputCollaborator; try { ApplicationUser searchedUser = db.Users.First(x => x.UserName == searchedCollaborator); Tutorial tut = db.Tutorials.First(x => x.Title == collaborate.TutorialSelection); CollaborativeTutorial collaborativeTutorial = new CollaborativeTutorial() { Tutorial = tut, TutorialId = tut.ID, }; collaborativeTutorial.Collaborators.Add(searchedUser); searchedUser.Collaborations.Add(collaborativeTutorial); db.Entry(searchedUser).State = EntityState.Modified; db.CollaborativeTutorials.Add(collaborativeTutorial); db.SaveChanges(); return RedirectToAction("Index"); } catch (InvalidOperationException) { return View(collaborate); } }