/// <summary>
 /// 1- Process PagingInParameter if not supplied
 /// 2- Get the HRCountry from service
 /// 3- Paginate previous result
 /// </summary>
 /// <param name="pageModel"></param>
 /// <returns></returns>
 public async Task <(int, PagingParameterOutModel <HRCountry>)> GetFromPaging(
     [FromQuery] PagingParameterInModel pageModel,
     [FromQuery] HRSortingParamModel orderBy)
 {
     if (_service != null)
     {
         if (orderBy != null && orderBy.IsInitialised())
         {
             if (!_service.IsSortable())
             {
                 return(StatusCodes.Status400BadRequest, null);
             }
             else if (!HRSortingParamModelDeserializer.IsValid(orderBy))
             {
                 return(StatusCodes.Status400BadRequest, null);
             }
         }
         //1-
         if (pageModel == null)
         {
             pageModel = GetDefaultPagingInParameter();
         }
         //!Add tu on this
         if (pageModel.PageSize > _maxPageSize)
         {
             return(StatusCodes.Status413PayloadTooLarge, null);
         }
         try
         {
             //2-
             Task <PagingParameterOutModel <HRCountry> > countriesAction = _service.GetCountriesAsync(pageModel, orderBy);
             await countriesAction;
             //3-
             return(StatusCodes.Status200OK, countriesAction.Result);
         }
         catch (IndexOutOfRangeException)
         {
             //!Add tu on this
             return(StatusCodes.Status416RequestedRangeNotSatisfiable, null);
         }
         catch (Exception)
         {
             return(StatusCodes.Status500InternalServerError, null);
         }
     }
     else
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 1- Process PagingInParameter if not supplied
        /// 2- Get the HRCountry from service
        /// 3- Paginate previous result
        /// </summary>
        /// <param name="pageModel">the paging model</param>
        /// <param name="orderBy">The order by clause</param>
        /// <param name="service">the Core countries service</param>
        /// <param name="maxPageSize">the maxPage size allowed for pagination.</param>
        /// <returns></returns>
        public async Task <(int, PagingParameterOutModel <HRCountry>)> GetFromPagingAsync(
            PagingParameterInModel pageModel,
            HRSortingParamModel orderBy,
            ICoreCountriesService service,
            ushort maxPageSize)
        {
            if (service != null && _util != null)
            {
                if (!_util.CanOrder(orderBy, service))
                {
                    return(StatusCodes.Status400BadRequest, null);
                }

                //!Add tu on this
                if (pageModel.PageSize > maxPageSize)
                {
                    return(StatusCodes.Status413PayloadTooLarge, null);
                }
                try
                {
                    //2-
                    Task <PagingParameterOutModel <HRCountry> > countriesAction = service.GetCountriesAsync(pageModel, orderBy);
                    await countriesAction;
                    //3-
                    return(StatusCodes.Status200OK, countriesAction.Result);
                }
                catch (IndexOutOfRangeException)
                {
                    //!Add tu on this
                    return(StatusCodes.Status416RequestedRangeNotSatisfiable, null);
                }
                catch (Exception)
                {
                    return(StatusCodes.Status500InternalServerError, null);
                }
            }
            else
            {
                return(StatusCodes.Status500InternalServerError, null);
            }
        }