Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="options"> the user custom options for search, sort ,filter page</param>
        /// <param name="type"> one element of the enumeration  to distinguish multiple type of url to create</param>
        /// <returns></returns>

        private string CreateUriTraineeship(TraineeshipSSFP options, RessourceUriType type)
        {
            switch (type)
            {
            case RessourceUriType.PreviousPage:
                return(Url.Link("GetAllTraineeShipAsync",
                                new
                {
                    PageNumber = options.PageNumber - 1,
                    options.PageSize,
                    options.SortBy,
                    options.FilterBy
                }));

            case RessourceUriType.NextPage:
                return(Url.Link("GetAllTraineeShipAsync",
                                new
                {
                    PageNumber = options.PageNumber + 1,
                    options.PageSize,
                    options.SortBy,
                    options.FilterBy
                }));

            default:
                return(Url.Link("GetAllTraineeShipAsync",
                                new
                {
                    options.PageNumber,
                    options.PageSize,
                    options.SortBy,
                    options.FilterBy
                }));
            }
        }
        public static IQueryable <Models.Traineeship> SearchTraineeshipBy(this IQueryable <Models.Traineeship> traineeships, TraineeshipSSFP options)
        {
            switch (options.SearchBy)
            {
            case TraineeshipSearchs.NoSearch:
                return(traineeships);

            case TraineeshipSearchs.License:
                return(traineeships
                       .Where(t => t.License.Title.Contains(options.License)));

            case TraineeshipSearchs.Price:
                return(traineeships
                       .Where(t => t.Price.ToString().Contains(options.Price)));

            default:
                throw new ArgumentOutOfRangeException
                          (nameof(options.SearchBy), options.SearchBy, null);
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult <IReadOnlyCollection <TraineeShipDto> > > GetAllTraineeShipAsync([FromQuery] TraineeshipSSFP options)
        {
            var traineeships = await _TraineeshipService.GetAllTraineeShipAsync(options);

            if (traineeships == null)
            {
                return(NotFound("Collection was empty :)"));
            }
            var previousPageLink = options.HasPrevious ? CreateUriTraineeship(options, RessourceUriType.PreviousPage) : null;
            var nextPageLink     = options.HasNext ? CreateUriTraineeship(options, RessourceUriType.NextPage) : null;

            var paginationMetadata = new
            {
                options.TotalCount,
                options.PageSize,
                options.PageNumber,
                options.TotalPages,
                options.FilterBy,
                options.SortBy,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata));

            return(Ok(traineeships));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get all(collection of traineeships)
        /// </summary>
        /// <param name="options"> options as traineeshipSSFP </param>
        /// <returns></returns>
        public async Task <IReadOnlyCollection <TraineeShipDto> > GetAllTraineeShipAsync(TraineeshipSSFP options)
        {
            var traineeships = _paraContext.Traineeships
                               .AsNoTracking()
                               .SortTraineeshipBy(options.SortBy)
                               .FilterTraineeshipBy(options.FilterBy)
                               .SearchTraineeshipBy(options)
                               .Select(T => new TraineeShipDto
            {
                Traineeshipid        = T.ID,
                TraineeShipStartDate = T.StartDate,
                TraineeShipPrice     = T.Price,
                TraineeShipEndDate   = T.EndDate,
                TraineeshipIsActive  = T.IsActive,
                LicenseId            = T.LicenseID,
                License = T.License
            });

            options.SetPagingValues(traineeships);

            var pagedQuery = traineeships.Page(options.PageNumber - 1, options.PageSize);

            return(await pagedQuery.ToListAsync());
        }