Exemple #1
0
        public async Task <QueryResult <ProblemCardRawData> > ProblemBasedOn(ProblemBetaFilter filter)
        {
            var result = new QueryResult <ProblemCardRawData>();
            var query  = getProblemBetDefaultQuery()
                         .OrderByDescending(prop => prop.Likes.Count).AsQueryable();


            // Filter query -------------- Use this method for the time being
            query = FilterProblemBeta(query, filter);

            // Get Total items
            result.TotalItems = await query.CountAsync();

            // Pagination
            query = query.AddPagination(filter);


            result.Items = await query.Select(s => new ProblemCardRawData()
            {
                Problem  = s,
                Likes    = s.Likes.Count,
                Comments = s.Comments.Count,
                Ideas    = s.Ideas.Count
            }).ToListAsync();

            return(result);
        }
Exemple #2
0
        private IQueryable <ProblemBeta> FilterProblemBeta(IQueryable <ProblemBeta> query, ProblemBetaFilter filter)
        {
            if (filter.CountryId.HasValue)
            {
                query = query.Where(prop => prop.CountryId == filter.CountryId.Value);
            }

            if (filter.CountryId.HasValue && filter.StateId.HasValue)
            {
                query = query.Where(prop => prop.CountryId == filter.CountryId.Value && prop.StateId == filter.StateId.Value);
            }

            if (!String.IsNullOrEmpty(filter.Name))
            {
                query = query.Where(
                    prop => prop.User.PersonalDetail.FirstName.ToUpper().Contains(filter.Name.ToUpper()) ||
                    prop.User.PersonalDetail.LastName.ToUpper().Contains(filter.Name.ToUpper()));
            }

            if (!String.IsNullOrEmpty(filter.Eco))
            {
                query = query.Where(prop => prop.Eco.ToUpper() == filter.Eco.ToUpper());
            }

            if (!String.IsNullOrEmpty(filter.Ico))
            {
                query = query.Where(prop => prop.Ico.ToUpper() == filter.Ico.ToUpper());
            }

            if (!String.IsNullOrEmpty(filter.EcoUn))
            {
                query = query.Where(prop => prop.EcoUn.ToLower() == filter.EcoUn.ToLower());
            }

            return(query);
        }