Example #1
0
 public string BuildUserStatisticString(
     UserStatisticModel userStatistic,
     string statisticTemplate)
 {
     return(string.Format(
                statisticTemplate,
                userStatistic.FirstName ?? userStatistic.Email,
                userStatistic.LastMonthTripsWhereHasAdminRoleCount,
                userStatistic.TotalTripsWhereHasAdminRoleCount,
                userStatistic.LastMonthUsersInHisRoutesCount,
                userStatistic.TotalUsersInHisRoutesCount,
                userStatistic.LastMonthRoutesWhereHasAdminRoleCount,
                userStatistic.TotalRoutesWhereHasAdminRoleCount,
                userStatistic.LastMonthRoutesWhereNotAdminCount,
                userStatistic.TotalRoutesWhereNotAdminCount,
                userStatistic.LastMonthCompletedTasksCount,
                userStatistic.TotalCompletedTasksCount,
                userStatistic.LastMonthCompletedItemsCount,
                userStatistic.TotalCompletedItemsCount));
 }
Example #2
0
        /// <summary>
        /// Creates UserStatisticModel instance and sets all the statistic data.
        /// </summary>
        /// <param name="userEntity">User to get statistic for.</param>
        /// <returns>UserStatisticModel instance, which represents user statistic data.</returns>
        private static UserStatisticModel GetUserStatisticModel(UserEntity userEntity)
        {
            var oneMonthAgo = DateTimeOffset.Now.AddMonths(-1);

            var lastMonthRouteSubscriptions = userEntity
                                              .TripSubscriptions
                                              .SelectMany(tripSubscription =>
                                                          tripSubscription.RouteSubscriptions
                                                          .Where(routeSubscription =>
                                                                 routeSubscription.DateSubscribed >= oneMonthAgo)).ToList();

            var totalRouteSubscriptions = userEntity
                                          .TripSubscriptions
                                          .SelectMany(tripSubscription => tripSubscription.RouteSubscriptions).ToList();

            var tripSubscriptions = userEntity
                                    .TripSubscriptions
                                    .ToList();

            var userStatisticModel = new UserStatisticModel()
            {
                Email = userEntity.Email,

                FirstName = userEntity.FirstName,

                LastMonthTripsWhereHasAdminRoleCount =
                    CountTripsWhereHasAdminRole(tripSubscriptions, oneMonthAgo),

                LastMonthRoutesWhereHasAdminRoleCount =
                    CountRoutesWhereHasAdminRole(lastMonthRouteSubscriptions),

                LastMonthRoutesWhereNotAdminCount =
                    CountRoutesWhereNotAdmin(lastMonthRouteSubscriptions),

                LastMonthCompletedTasksCount =
                    CountCompletedTasksForPeriod(lastMonthRouteSubscriptions, oneMonthAgo),

                LastMonthCompletedItemsCount =
                    CountCompletedItemsForPeriod(lastMonthRouteSubscriptions, oneMonthAgo),

                LastMonthUsersInHisRoutesCount =
                    CountUsersInHisRoutes(tripSubscriptions, oneMonthAgo),

                TotalTripsWhereHasAdminRoleCount =
                    CountTripsWhereHasAdminRole(tripSubscriptions, DateTimeOffset.MinValue),

                TotalRoutesWhereHasAdminRoleCount =
                    CountRoutesWhereHasAdminRole(totalRouteSubscriptions),

                TotalRoutesWhereNotAdminCount =
                    CountRoutesWhereNotAdmin(totalRouteSubscriptions),

                TotalCompletedTasksCount =
                    CountCompletedTasksForPeriod(totalRouteSubscriptions, DateTimeOffset.MinValue),

                TotalCompletedItemsCount =
                    CountCompletedItemsForPeriod(totalRouteSubscriptions, DateTimeOffset.MinValue),

                TotalUsersInHisRoutesCount =
                    CountUsersInHisRoutes(tripSubscriptions, DateTimeOffset.MinValue)
            };

            return(userStatisticModel);
        }