public void ChangeCommentSortTypeCookie(IResponseCookies responseCookies, CommentSortType commentSortType) { var sortTypeKey = WebConstants.CookieKeyCommentSortType; var sortTypeValue = commentSortType.ToString(); responseCookies.Append(sortTypeKey, sortTypeValue); }
public PostViewModel MapPostViewModelForQuest(Post post, CommentSortType sortType, IEnumerable <Comment> comments) { int commentCount = CountComments.Count(comments); var model = this.mapper.Map <PostViewModel>(post); model.SelectedCommentSortType = sortType; model.CommentsCount = commentCount; model.Comments = this.mapper.Map <IEnumerable <CommentViewModel> >(comments); return(model); }
public PostViewModel MapPostViewModelForSignInUser( string userId, Post post, CommentSortType sortType, IEnumerable <Comment> comments) { var model = this.MapPostViewModelForQuest(post, sortType, comments); model.UserVoteValue = this.GetUserVoteValueOrDefault(post.Votes, userId); return(model); }
public IActionResult ChangeCommentSortType(string sortType, string postId) { CommentSortType commentSortType = CommentSortType.Best; var isParseSuccessfull = Enum.TryParse(sortType, out commentSortType); if (isParseSuccessfull == false) { this.AddStatusMessage(AlertConstants.ErrorMessageWrongParameter, AlertConstants.AlertTypeDanger); } else { this.cookieService.ChangeCommentSortTypeCookie(this.Response.Cookies, commentSortType); } return(this.RedirectToAction("Index", new { postId })); }
public static ISortCommentsStrategy GetSortPostsStrategy( IRedditCloneUnitOfWork unitOfWork, CommentSortType sortType) { switch (sortType) { case CommentSortType.New: return(new SortCommentsByNew(unitOfWork)); case CommentSortType.Old: return(new SortCommentsByOld(unitOfWork)); case CommentSortType.Top: return(new SortCommentsByTop(unitOfWork)); case CommentSortType.Controversial: return(new SortCommentsByControversial(unitOfWork)); case CommentSortType.Best: return(new SortCommentsByBest(unitOfWork)); default: throw new InvalidEnumArgumentException(); } }
public ActionResult <List <CommentPost> > GetComments(int postId, int pageNumber, int pageSize, CommentSortType sortType) { try { var result = _db.Comments .Include(u => u.User) .Where(p => p.Post.Id == postId) .Select(comm => new CommentPost { Id = comm.Id, Text = comm.Text, Date = comm.Date, Author = comm.User.FirstName + " " + comm.User.LastName, ImgUrl = comm.User.ImgUrl, Likes = comm.Likes }) .AsNoTracking(); switch (sortType) { case CommentSortType.POPULAR_ASCENDING: result = result.OrderBy(p => p.Likes); break; case CommentSortType.POPULAR_DESCENDING: result = result.OrderByDescending(p => p.Likes); break; case CommentSortType.NEWEST_ASCENDING: result = result.OrderBy(p => p.Date); break; case CommentSortType.NEWEST_DESCENDING: result = result.OrderByDescending(p => p.Date); break; } result = result .Skip(pageNumber * pageSize) .Take(pageSize); return(result.ToList()); } catch (Exception ex) { return(StatusCode(500, $"Internal server error {ex}")); } }