Exemplo n.º 1
0
        /// <summary>
        /// Method for get one UserStatistic object for a specific year for a specific user based on data from HistoryTrip retository.
        /// </summary>
        /// <param name="year">For this year you need to get statistics.</param>
        /// <param name="userId">Statistics for user with userId.</param>
        /// <returns>Return UserStatistic object based on data from HistoryTrip retository.</returns>
        public UserStatistic GetByYear(int year, string userId)
        {
            List <SelectListItem> years = GetAllYears(userId);

            //history clear
            if (years.Count == 0)
            {
                return(GetDefaultUserStatistic(userId));
            }

            var historyTrip = _historyTripService.GetHistoryByYear(year, userId);
            var statistic   = new UserStatistic()
            {
                Year           = year,
                Years          = years,
                ObserveTrips   = _historyTripService.GetDurationTrips(historyTrip),
                CountTrips     = _historyTripService.GetCountTrips(historyTrip),
                LocationsTrips = _historyTripService.GetLocationsTrips(historyTrip),
                LastTrip       = _historyTripService.GetLatsTripByYear(year, userId),
                User           = _repositoryUser.GetById(userId),
            };

            return(statistic);
        }