Beispiel #1
0
        public async Task <ICollection <BlogDTO> > GetBlogByCriteriaAsync(BlogsCriteriaInputModel model)
        {
            if (model.PostIds.Any() &&
                model.UsersIds.Any() &&
                model.DateCreated == null &&
                string.IsNullOrWhiteSpace(model.Name)
                )
            {
                throw new ArgumentNullException("Critera is empty");
            }
            var blogs = this.repository.All();

            if (model.UsersIds.Any())
            {
                blogs = blogs
                        .Where(u => model.UsersIds.Contains((long)u.UserCreatorId));
            }

            if (model.PostIds.Any())
            {
                blogs = blogs
                        .Where(b => b.Posts.Any(p => model.PostIds.Contains(p.Id)));
            }

            if (model.DateCreated != null)
            {
                blogs = blogs
                        .Where(b => b.DataCreated.Date == model.DateCreated.Value.Date);
            }

            if (!string.IsNullOrWhiteSpace(model.Name))
            {
                blogs = blogs
                        .Where(b => b.Name.Contains(model.Name));
            }
            return(await blogs.Select(BlogMapper.SelectBlogDtoFromBlog).ToListAsync());
        }
Beispiel #2
0
 public async Task <ICollection <BlogDTO> > GetBlogsByCriteria([FromBody] BlogsCriteriaInputModel blog)
 {
     return(await service.GetBlogByCriteriaAsync(blog));
 }