public IEnumerable <ViewPostModel> GetPosts(GetPostsModel model) { var posts = _repository.GetAll(); var filteredPosts = new FilterBuilder() .SetName(model.Title) .SetDate(model.Date) .SetStartDate(model.Start) .SetEndDate(model.End) .Build(posts); var result = new List <ViewPostModel>(); filteredPosts.ToList().ForEach(post => { result.Add(new ViewPostModel { Category = $"/api/categories/{post.CategoryId}", Content = post.Content, Id = post.Id, PublishDate = post.PublishDate, Status = post.Status, StatusReason = post.StatusReason, Summary = post.Summary, Title = post.Title }); }); return(result); }
public async Task <List <dynamic> > GetAll(GetPostsModel model) { var data = GetPostList(); var filter = data.AsQueryable().OrderBy(model.SortBy + " " + model.OrderBy).Skip(model.Skip); var filtered = model.Take == 0 ? await filter.ToDynamicListAsync() : await filter.Take(model.Take).ToDynamicListAsync(); return(filtered); }
public async Task <IActionResult> GetPosts([FromBody] GetPostsModel model) { var whichUserReachedThisMethod = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var result = await _postsRepository.GetAll(model); if (result != null) { return(Ok(result)); } return(BadRequest()); }
public IActionResult Get([FromQuery] GetPostsModel model) { try { var posts = _service.GetPosts(model); if (!posts.Any()) { return(NoContent()); } return(Ok(posts)); } catch (Exception ex) { return(new ContentResult { StatusCode = StatusCodes.Status500InternalServerError, Content = ex.Message, ContentType = "text/plain", }); } }