Пример #1
0
        public JsonResult GetCommunities([FromQuery] QueryParamsHelper queryParameters)
        {
            JSONObjectResult result = new JSONObjectResult
            {
                Status = System.Net.HttpStatusCode.OK
            };

            try
            {
                var data   = _communityService.GetCommunities(queryParameters, out long totalCount);
                var mapped = _mapper.Map <List <CommunityViewModel> >(data);

                var pagination = new
                {
                    totalCount,
                    pageSize    = queryParameters.PageCount,
                    currentPage = queryParameters.Page,
                    totalPages  = queryParameters.GetTotalPages(totalCount)
                };

                result.Data = new
                {
                    communities = mapped,
                    pagination
                };
            }
            catch (Exception e)
            {
                result.Status = System.Net.HttpStatusCode.BadRequest;
                result.Errors.Add(e.Message);
            }

            return(new JsonResult(result));
        }
        public List <Vinyl> GetVinyls(QueryParamsHelper queryParameters, string search)
        {
            try
            {
                var query = _context.Vinyl
                            .Include(x => x.SubGenre.Genre)
                            .Include(x => x.Country)
                            .AsQueryable();

                if (!string.IsNullOrEmpty(search))
                {
                    query = query.Where(x => x.Band.ToLower().Contains(search.ToLower()));
                }

                var vinylList = query.Where(x => x.Id_User == _appPrincipal.Id)
                                .OrderByDescending(x => x.DateCreated)
                                .Skip(queryParameters.PageCount * (queryParameters.Page - 1))
                                .Take(queryParameters.PageCount)
                                .ToList();

                return(vinylList);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
 public static bool IsDescending(this QueryParamsHelper queryParameters)
 {
     if (!string.IsNullOrEmpty(queryParameters.OrderBy))
     {
         return(queryParameters.OrderBy.Split(' ').Last().ToLowerInvariant().StartsWith("desc"));
     }
     return(false);
 }
        public List <Community> GetCommunities(QueryParamsHelper queryParams, out long totalCount)
        {
            try
            {
                var communities = _context.Community
                                  .Where(x => x.Deleted == false)
                                  .Include(x => x.User)
                                  .AsNoTracking();

                totalCount = communities.Count();

                var communityList = communities
                                    .Skip(queryParams.PageCount * (queryParams.Page - 1))
                                    .Take(queryParams.PageCount)
                                    .ToList();

                return(communityList);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #5
0
 public static bool HasQuery(this QueryParamsHelper queryParameters)
 {
     return(!string.IsNullOrEmpty(queryParameters.Query));
 }
Пример #6
0
 public static double GetTotalPages(this QueryParamsHelper queryParameters, long totalCount)
 {
     return(Math.Ceiling(totalCount / (double)queryParameters.PageCount));
 }
Пример #7
0
 public static bool HasNext(this QueryParamsHelper queryParameters, int totalCount)
 {
     return(queryParameters.Page < (int)GetTotalPages(queryParameters, totalCount));
 }
Пример #8
0
 public static bool HasPrevious(this QueryParamsHelper queryParameters)
 {
     return(queryParameters.Page > 1);
 }