/// <summary>
 /// 1- Check consistency before calling service
 ///     1.1- Service must be supplied
 ///     1.2- If OrderBy is supplied, check that service have the skill to order and that the OrderBy is valid.
 ///     1.3- PageModel.PageSize must be lower than MaxPage
 /// 2- Get the HRBorders from service
 ///     2.1- If result is OK, return code200
 ///     2.2- Else if IndexOutOfRangeException is catch return Status416RequestedRangeNotSatisfiable
 ///     2.3 Else for any other Exception return Status500InternalServerError
 /// </summary>
 /// <param name="pageModel">The Paging Model.</param>
 /// <param name="orderBy">The order by clause. Sample : "ISO2;DESC".</param>
 /// <param name="borderService">The countries service.</param>
 /// <param name="maxPageSize">The max PageSize of pagination.</param>
 /// <returns>(http Status Code, PagingParameterOutModel).</returns>
 public async Task <(int, PagingParameterOutModel <HRBorder>)> GetFromPagingAsync(
     PagingParameterInModel pageModel,
     HRSortingParamModel orderBy,
     ICoreBordersService borderService,
     ushort maxPageSize)
 {
     //1-
     //1.1-
     if (borderService == null || _util == null)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
     //1.2-
     if (!_util.CanOrder(orderBy, borderService))
     {
         return(StatusCodes.Status400BadRequest, null);
     }
     //1.3-
     if (pageModel.PageSize > maxPageSize)
     {
         return(StatusCodes.Status413PayloadTooLarge, null);
     }
     try
     {
         //2-
         Task <PagingParameterOutModel <HRBorder> > bordersAction = borderService.GetBordersAsync(pageModel, orderBy);
         await bordersAction;
         //2.1-
         return(StatusCodes.Status200OK, bordersAction.Result);
     }
     //2.2-
     catch (IndexOutOfRangeException)
     {
         return(StatusCodes.Status416RequestedRangeNotSatisfiable, null);
     }
     //2.3-
     catch (Exception)
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }
示例#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);
            }
        }