public async Task TestGetComments() { TestingContext testingContext = new TestingContext(); SetUpTestingContext(testingContext); ApplicationDbContext appDbContext = testingContext.GetSimple <ApplicationDbContext>(); ICommentsService commentsService = testingContext.GetService <CommentsService>(); Question question = appDbContext.Questions.First(); for (int i = 0; i < 20; i++) { CommentDto commentDto = new CommentDto() { IdQuestion = question.Id, CommentText = "Hello Comment", }; await commentsService.AddCommentAsync(commentDto); } GetCommentsDto getCommentsDto = new GetCommentsDto { IdQuestion = question.Id, Page = 0, }; //Act PagedResultDto <CommentDto> comments = await commentsService.GetCommentssAsync(getCommentsDto); //Assert Assert.Equal(5, comments.Data.Count); Assert.Equal(4, comments.Numpages); Assert.Equal(20, comments.Count); }
// public PaginatedList<GetCommentsDto> GetAll(int page, string filterString) // { // throw new NotImplementedException(); // } //public IEnumerable<GetCommentsDto> GetComments(string text) //{ // IQueryable<GetCommentsDto> result = context.Comments.Select(x => new Comment // { // Id = x.Id, // Text = x.Text, // Important = x.Important, // ExpenseId = (from Expense in context.Expenses // where Expense.Id == x.ExpenseId // select Expense.Id).FirstOrDefault() // }); // //var result = context.Comments.Select(x // if (text != null) // { // result = result.Where(comment => comment.Text.Contains(text)); // } // return result.Select(comment => GetCommentsDto.DtoFromModel(comment)); //} public PaginatedList <GetCommentsDto> GetComments(int page, string filterString) { //IQueryable<GetCommentsDto> result = context.Comments.Select(x => new GetCommentsDto //{ // Id = x.Id, // Text = x.Text, // Important = x.Important, // ExpenseId = (from ex in context.Expenses // where ex.Comments.Contains(x) // select ex.Id).FirstOrDefault() //}); //if (text != "") //{ // result = result.Where(c => c.Text.Contains(text)); //} //return result; IQueryable <Comment> result = context .Comments .Where(c => string.IsNullOrEmpty(filterString) || c.Text.Contains(filterString)) .OrderBy(c => c.Id) .Include(c => c.Expense); var paginatedResult = new PaginatedList <GetCommentsDto>(); paginatedResult.CurrentPage = page; paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <GetCommentsDto> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <GetCommentsDto> .EntriesPerPage) .Take(PaginatedList <GetCommentsDto> .EntriesPerPage); paginatedResult.Entries = result.Select(c => GetCommentsDto.DtoFromModel(c)).ToList(); return(paginatedResult); }
public async Task <List <CommentDto> > GetCommentListByGiftId(GetCommentsDto getCommentsDto) { var query = Db.Set <GiftLinkComment>().Where(x => x.GiftId == getCommentsDto.Id).Where(y => y.Comment.ParentCommentId == null); query = query.OrderByDescending(x => x.Comment.UpdateTime).Skip(getCommentsDto.Offset).Take(getCommentsDto.Length); var collection = await query.ToListAsync(); return(ConvertToCommentDto(collection)); }
public async Task <PagedResultDto <CommentDto> > GetCommentssAsync(GetCommentsDto parameters) { PagedResultDto <CommentDto> resultDto = new PagedResultDto <CommentDto>(); IQueryable <Comment> queryBeforeSkipAndTake = _dbContext.Comments .Where(x => x.Question.Id == parameters.IdQuestion) .OrderByDescending(x => x.InsertDate) .ThenBy(x => x.Id); PagedResultDto <CommentDto> result = await Util.PagedResultUtil.ToPagedResult(queryBeforeSkipAndTake, parameters.Page, ToDto); return(result); }
//public IEnumerable<GetCommentsDto> GetComments(string text) //{ // IQueryable<GetCommentsDto> result = context.Comments.Select(x => new Comment // { // Id = x.Id, // Text = x.Text, // Important = x.Important, // ExpenseId = (from Expense in context.Expenses // where Expense.Id == x.ExpenseId // select Expense.Id).FirstOrDefault() // }); // //var result = context.Comments.Select(x // if (text != null) // { // result = result.Where(comment => comment.Text.Contains(text)); // } // return result.Select(comment => GetCommentsDto.DtoFromModel(comment)); //} public PaginatedList <GetCommentsDto> GetAll(int page, string filterString) { IQueryable <Comment> result = context .Comments .Where(c => string.IsNullOrEmpty(filterString) || c.Text.Contains(filterString)) .OrderBy(c => c.Id) .Include(c => c.Expense); var paginatedResult = new PaginatedList <GetCommentsDto>(); paginatedResult.CurrentPage = page; paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <GetCommentsDto> .EntriesPerPage + 1; result = result .Skip((page - 1) * PaginatedList <GetCommentsDto> .EntriesPerPage) .Take(PaginatedList <GetCommentsDto> .EntriesPerPage); paginatedResult.Entries = result.Select(c => GetCommentsDto.DtoFromModel(c)).ToList(); return(paginatedResult); }
public IEnumerable <GetCommentsDto> GetAll(String filter) { IQueryable <Expense> result = context.Expenses.Include(c => c.Comments); List <GetCommentsDto> resultComments = new List <GetCommentsDto>(); List <GetCommentsDto> resultCommentsAll = new List <GetCommentsDto>(); foreach (Expense expense in result) { expense.Comments.ForEach(c => { if (c.Text == null || filter == null) { GetCommentsDto comment = new GetCommentsDto { Id = c.Id, Important = c.Important, Text = c.Text, ExpenseId = expense.Id }; resultCommentsAll.Add(comment); } else if (c.Text.Contains(filter)) { GetCommentsDto comment = new GetCommentsDto { Id = c.Id, Important = c.Important, Text = c.Text, ExpenseId = expense.Id }; resultComments.Add(comment); } }); } if (filter == null) { return(resultCommentsAll); } return(resultComments); }
public IEnumerable <GetCommentsDto> GetComments(string text) { IQueryable <Comment> result = context.Comments.Select(x => new Comment { Id = x.Id, Text = x.Text, Important = x.Important, Expense = (from Expense in context.Expenses where Expense.Id == x.Expense.Id select Expense).FirstOrDefault() }); //var result = context.Comments.Select(x if (text != null) { result = result.Where(comment => comment.Text.Contains(text)); } return(result.Select(comment => GetCommentsDto.DtoFromModel(comment))); }
public async Task <PagedResultDto <CommentDto> > GetComments([FromBody] GetCommentsDto parameters) { return(await _commentsService.GetCommentssAsync(parameters)); }
public async Task <IHttpActionResult> GetByWishId(GetCommentsDto idModel) { return(SuccessApiResult(await _commentRepository.GetCommentListByWishId(idModel))); }