Esempio n. 1
0
        public async Task <List <ObjectDorehamiSummery> > Search(RequestSearchDorehami request, ClaimsPrincipal actingUser)
        {
            var user = await Helper.GetUserByClaim(dbContext, actingUser);

            var q0 = dbContext.Dorehamies
                     .AsNoTracking();

            var q1 = q0;

            if (!string.IsNullOrEmpty(request.Name))
            {
                q1 = q1.Where(r => r.Name.Contains(request.Name));
            }

            if (!string.IsNullOrEmpty(request.Province))
            {
                q1 = q1.Where(r => r.Province == request.Province);
            }

            if (!string.IsNullOrEmpty(request.Category))
            {
                q1 = q1.Where(r => r.Category == request.Category);
            }

            if (request.Tags.Count != 0)
            {
                var tagsList = await tagService.GetTags(request.Tags);

                var tagIds = tagsList.Select(r => r.Id);
                q1 = q1.Where(r => r.TagDorehamies
                              .Any(t => tagIds.Contains(t.TagId.Value)));
                //q1 = q1.Where(dor => tagIds.All(
                //				ti => dor.TagDorehamies
                //					.Select(td => td.TagId)
                //					.Contains(ti)
                //				));
            }

            var qf = q1
                     .Select(Helper.SummeryFromDorehami(user.Id))
                     .OrderByDescending(r => r.DateCreated);

            return(await qf.ToListAsync());
        }
 public async Task <IActionResult> Search([FromBody] RequestSearchDorehami request)
 {
     // todo validations
     return(await ExecuteAsync(
                () => service.Search(request, User)));
 }