public ActionResult ActiveAthletesPaging([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)
        {
            requestModel.Draw++;

            var orderedEnumerable = requestModel.Columns.GetSortedColumns();
            var orderByColumn = int.Parse(orderedEnumerable.First().Data);
            var orderDirection = orderedEnumerable.First().SortDirection == 0 ? OrderDirection.Ascendant : OrderDirection.Descendant;
            var searchValue = requestModel.Search.Value;

            var request = new GetFilteredAthletesRequest
            {
                OrderByColumn = orderByColumn,
                OrderDirection = orderDirection,
                SearchValue = searchValue,
                Start = requestModel.Start,
                Length = requestModel.Length,
                WithExercisesOfTheDay = true,
                WithStatistics = true
            };

            var response = _athleteService.GetFilteredAthletes(request);

            var workoutOfTheDayViewModel =
                new WorkoutOfTheDayViewModelBuilder()
                    .WithDataTableRows(response.FilteredAthletes, response.ExercisesOfTheDay.ToList())
                    .Build();

            var recordsTotal = response.RecordsTotal;
            var recordsFiltered = response.RecordsFiltered;
            var paged = workoutOfTheDayViewModel.DataTableRows;

            return Json(new DataTablesResponse(requestModel.Draw, paged, recordsFiltered, recordsTotal), JsonRequestBehavior.AllowGet);
        }
Exemple #2
0
        public GetFilteredAthletesResponse GetFilteredAthletes(GetFilteredAthletesRequest request)
        {
            var response = new GetFilteredAthletesResponse();

            var includeProperties = "";
            if (request.WithStatistics)
            {
                includeProperties = "AthleteStatistics";
            }

            var activeAthletes = GetActiveAthletes(includeProperties).Athletes.ToList();

            var filteredAthletesResponse = FilterAthletes(request, activeAthletes);

            response.FilteredAthletes = filteredAthletesResponse.PagedAthletes;
            response.RecordsTotal = filteredAthletesResponse.ActiveAthletesCount;
            response.RecordsFiltered = filteredAthletesResponse.PagedAthletesCount;

            if (request.WithExercisesOfTheDay)
            {
                response.ExercisesOfTheDay = GetExercisesOfTheDay();
            }

            return response;
        }
        public IHttpActionResult GetActiveAthletes()
        {
            var request = new GetFilteredAthletesRequest
            {
                //OrderByColumn = orderByColumn,
                //OrderDirection = orderDirection,
                //SearchValue = searchValue,
                //Start = requestModel.Start,
                //Length = requestModel.Length,
                WithExercisesOfTheDay = true,
                WithStatistics = true
            };

            var response = _athleteService.GetFilteredAthletes(request);

            return Ok(response);
        }
Exemple #4
0
        private static FilterAthletesResponse FilterAthletes(GetFilteredAthletesRequest request, List<Athlete> activeAthletes)
        {
            var filterAthletes = new List<Athlete>();

            switch (request.OrderByColumn)
            {
                case 1:
                    {
                        if (request.OrderDirection == OrderDirection.Ascendant)
                        {
                            filterAthletes = activeAthletes
                                .Where(q => q.FirstName.Contains(request.SearchValue) || q.LastName.Contains(request.SearchValue))
                                .OrderBy(p => p.LastName)
                                .Skip(request.Start)
                                .Take(request.Length)
                                .ToList();
                        }
                        if (request.OrderDirection == OrderDirection.Descendant)
                        {
                            filterAthletes = activeAthletes
                                .Where(q => q.FirstName.Contains(request.SearchValue) || q.LastName.Contains(request.SearchValue))
                                .OrderByDescending(p => p.LastName)
                                .Skip(request.Start)
                                .Take(request.Length)
                                .ToList();
                        }
                        break;
                    }
                default:
                    {
                        filterAthletes = activeAthletes;
                        break;
                    }
            }

            return new FilterAthletesResponse
            {
                PagedAthletes = filterAthletes,
                PagedAthletesCount = filterAthletes.Count,
                ActiveAthletesCount = activeAthletes.Count
            };
        }