//Method that updates comment public bool UpdateComment(UserCommentDTO UpdatedComment) { bool check = false; using (TransactionScope Trans = new TransactionScope()) { try { using (var context = new CinemaEntities()) { var results = (from cm in context.Comments where cm.CommentID == UpdatedComment.commentID select cm); if (results != null) { Comment CommentToUpdate = new Comment(); CommentToUpdate = (Comment)results.First(); CommentToUpdate.Content = UpdatedComment.Content; context.ObjectStateManager.ChangeObjectState(CommentToUpdate, System.Data.EntityState.Modified); context.SaveChanges(); } } } catch { check = false; Trans.Dispose(); return(check); } check = true; Trans.Complete(); return(check); } }
//Method that gets all Comments of specific user public IList<UserCommentDTO> GetAllUserComments(System.Guid userID) { IList<UserCommentDTO> ListOfComments = new List<UserCommentDTO>(); using (var context = new CinemaEntities()) { var results = (from com in context.Comments.Include("Movie") where com.UserID == userID select com); if (results!=null) { foreach (var item in results) { UserCommentDTO row = new UserCommentDTO(); row.userID = userID.ToString(); row.commentID = item.CommentID; row.movieID = item.MovieID; row.Content = item.Content; row.MovieTitle = item.Movie.Title; ListOfComments.Add(row); } } } return ListOfComments; }
//Method that gets all Comments of specific user public IList <UserCommentDTO> GetAllUserComments(System.Guid userID) { IList <UserCommentDTO> ListOfComments = new List <UserCommentDTO>(); using (var context = new CinemaEntities()) { var results = (from com in context.Comments.Include("Movie") where com.UserID == userID select com); if (results != null) { foreach (var item in results) { UserCommentDTO row = new UserCommentDTO(); row.userID = userID.ToString(); row.commentID = item.CommentID; row.movieID = item.MovieID; row.Content = item.Content; row.MovieTitle = item.Movie.Title; ListOfComments.Add(row); } } } return(ListOfComments); }
private void UpdateDleteComment(TreeViewUpdateArgs tua) { IUser UserServices = new UserServices(); bool check = false; if (tua.ActionToPerform == "Delete") { int commentID = tua.ChildID; check = UserServices.DeleteComment(commentID); } else if (tua.ActionToPerform == "Update") { UserCommentDTO CommentToUpdate = new UserCommentDTO(); CommentToUpdate.commentID = tua.ChildID; CommentToUpdate.Content = tua.ChildContent; check = UserServices.UpdateComment(CommentToUpdate); } if (check) { Guid UserID = UserServices.GetUserID(tua.UserName); IList <UserCommentDTO> ListOfComments = UserServices.GetAllUserComments(UserID); IList <String> ListOfMovies = UserServices.GetMoviesToWhichTheUserCommented(UserID); Myview.Model.IsValidTransastion = true; Myview.Model.ListOfComments = new List <CommentLine>(); Myview.Model.ListOfMovies = new List <String>(); foreach (var item in ListOfComments) { //creating list of comments CommentLine row = new CommentLine(); row.CommentID = item.commentID; row.MovieTitle = item.MovieTitle; row.CommentContent = item.Content; row.MovieID = item.movieID; Myview.Model.ListOfComments.Add(row); } foreach (var item in ListOfMovies) { String row1 = null; row1 = item; bool checkIfContains = Myview.Model.ListOfMovies.Contains(row1); if (!checkIfContains) { Myview.Model.ListOfMovies.Add(row1); } } } }
public async Task<IHttpActionResult> PostPost(UserCommentDTO comment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } PostComment p = new PostComment(); var user = from std in db.Users where std.Email == comment.Email select std; p.UserID = user.First().ID; p.PostID = comment.postiD; p.Text = comment.commentCommentText; db.PostComments.Add(p); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = comment.postiD }, comment); }
private void UpdateDleteComment(TreeViewUpdateArgs tua) { IUser UserServices = new UserServices(); bool check = false; if (tua.ActionToPerform == "Delete") { int commentID = tua.ChildID; check = UserServices.DeleteComment(commentID); } else if (tua.ActionToPerform == "Update") { UserCommentDTO CommentToUpdate = new UserCommentDTO(); CommentToUpdate.commentID = tua.ChildID; CommentToUpdate.Content = tua.ChildContent; check = UserServices.UpdateComment(CommentToUpdate); } if (check) { Guid UserID = UserServices.GetUserID(tua.UserName); IList<UserCommentDTO> ListOfComments = UserServices.GetAllUserComments(UserID); IList<String> ListOfMovies = UserServices.GetMoviesToWhichTheUserCommented(UserID); Myview.Model.IsValidTransastion = true; Myview.Model.ListOfComments = new List<CommentLine>(); Myview.Model.ListOfMovies = new List<String>(); foreach (var item in ListOfComments) { //creating list of comments CommentLine row = new CommentLine(); row.CommentID = item.commentID; row.MovieTitle = item.MovieTitle; row.CommentContent = item.Content; row.MovieID = item.movieID; Myview.Model.ListOfComments.Add(row); } foreach (var item in ListOfMovies) { String row1 = null; row1 = item; bool checkIfContains = Myview.Model.ListOfMovies.Contains(row1); if (!checkIfContains) { Myview.Model.ListOfMovies.Add(row1); } } } }
//Method that updates comment public bool UpdateComment(UserCommentDTO UpdatedComment) { bool check = false; using (TransactionScope Trans = new TransactionScope()) { try { using (var context = new CinemaEntities()) { var results = (from cm in context.Comments where cm.CommentID == UpdatedComment.commentID select cm); if (results != null) { Comment CommentToUpdate = new Comment(); CommentToUpdate = (Comment)results.First(); CommentToUpdate.Content = UpdatedComment.Content; context.ObjectStateManager.ChangeObjectState(CommentToUpdate, System.Data.EntityState.Modified); context.SaveChanges(); } } } catch { check = false; Trans.Dispose(); return check; } check = true; Trans.Complete(); return check; } }