Example #1
0
        internal static PlayDataDetailsViewModel ToDetailsViewModel(PlayData playData)
        {
            var pdVM = new PlayDataDetailsViewModel
            {
                ID              = playData.ID,
                GameID          = playData.GameID,
                GameTitle       = playData.Game.Title,
                PlayerName      = playData.Hoarder.Name,
                Status          = playData.Status,
                Priority        = playData.Priority.Name,
                Rating          = playData.Rating == null? "" : playData.Rating.ToString(),
                OwnershipStatus = playData.OwnershipStatus.Name,
                TotalPlaytime   = PlaytimeHelper.GetLongPlaytimeString(playData.TotalPlaytime),
                FirstPlayed     = playData.FirstPlayed == null? "Unknown" : ((DateTime)playData.FirstPlayed).ToString(EntityConstants.DateFormatString),
                LastPlayed      = playData.LastPlayed == null? "Unknown" : ((DateTime)playData.LastPlayed).ToString(EntityConstants.DateFormatString),
                Notes           = playData.Notes
            };

            if (playData.Playthroughs != null && playData.Playthroughs.Count != 0)
            {
                foreach (var pt in playData.Playthroughs)
                {
                    var ptVM = PlaythroughMapper.ToPlayDataDetailsViewModel(pt);

                    pdVM.Playthroughs.Add(ptVM);
                }
            }

            return(pdVM);
        }
Example #2
0
        internal static GamePlayDataDetailsViewModel ToGameDetailsViewModel(PlayData playData)
        {
            var pdVM = new GamePlayDataDetailsViewModel
            {
                ID            = playData.ID,
                PlayerName    = playData.Hoarder.Name,
                Status        = playData.Status,
                Priority      = playData.Priority.Name,
                Rating        = playData.Rating == null ? "" : playData.Rating.ToString(),
                TotalPlaytime = PlaytimeHelper.GetLongPlaytimeString(playData.TotalPlaytime),
                Notes         = playData.Notes
            };

            if (playData.Playthroughs != null && playData.Playthroughs.Count != 0)
            {
                foreach (var pt in playData.Playthroughs)
                {
                    var ptVM = PlaythroughMapper.ToGameDetailsViewModel(pt);

                    pdVM.Playthroughs.Add(ptVM);
                }
            }

            return(pdVM);
        }
Example #3
0
        internal static GamePlaythroughDetailsViewModel ToGameDetailsViewModel(Playthrough playthrough)
        {
            var playtime = new TimeSpan(0, playthrough.PlaytimeInMinutes, 0);

            var ptVM = new GamePlaythroughDetailsViewModel
            {
                PlayDataID    = playthrough.PlayDataID,
                OrdinalNumber = playthrough.OrdinalNumber,
                Status        = playthrough.Status,
                Playtime      = PlaytimeHelper.GetShortPlaytimeString(playtime),
                PlayDates     = PlayDatesHelper.GetPlayDatesString(playthrough.DateStart, playthrough.DateEnd),
                Notes         = playthrough.Notes
            };

            return(ptVM);
        }
Example #4
0
        internal static PlayDataPlaythroughDetailsViewModel ToPlayDataDetailsViewModel(Playthrough playthrough)
        {
            var playtime = new TimeSpan(0, playthrough.PlaytimeInMinutes, 0);

            var ptVM = new PlayDataPlaythroughDetailsViewModel
            {
                PlayDataID    = playthrough.PlayDataID,
                OrdinalNumber = playthrough.OrdinalNumber,
                Status        = playthrough.Status,
                Playtime      = PlaytimeHelper.GetLongPlaytimeString(playtime),
                DateStart     = playthrough.DateStart == null ? "Unknown" : ((DateTime)playthrough.DateStart).ToString(EntityConstants.DateFormatString),
                DateEnd       = playthrough.DateEnd == null ? "Unknown" : ((DateTime)playthrough.DateEnd).ToString(EntityConstants.DateFormatString),
                Notes         = playthrough.Notes
            };

            return(ptVM);
        }
        public async Task <UserDashboardViewModel> GetUserDashboardAsync(int hoarderID)
        {
            // TODO: Split into separate methods for each section of the dashboard?

            var recentlyStartedPlaythroughs = await playthroughDbService.GetUserRecentlyStartedPlaythroughsAsync(hoarderID);

            var recentlyFinishedPlaythroughs = await playthroughDbService.GetUserRecentlyFinishedPlaythroughsAsync(hoarderID);

            var recentJournalEntries = await journalDbService.GetRecentJournalEntriesAsync(hoarderID);

            var recentEvents = CreateRecentEventsList(recentlyStartedPlaythroughs, recentlyFinishedPlaythroughs, recentJournalEntries);

            var totalPlayTime = await playDataDbService.CountUserTotalPlaytimeAsync(hoarderID);

            var numberOfOwnedGames = await playDataDbService.CountUserOwnedGamesAsync(hoarderID);

            var numberOfDroppedGames = await playDataDbService.CountUserDroppedGamesAsync(hoarderID);

            var numberOfWishlistItems = await wishlistDbService.CountUserWishlistItemsAsync(hoarderID);

            var userDashboardVM = new UserDashboardViewModel
            {
                TotalPlaytime         = PlaytimeHelper.GetLongPlaytimeString(totalPlayTime),
                NumberOfOwnedGames    = numberOfOwnedGames.ToString(),
                NumberOfDroppedGames  = numberOfDroppedGames.ToString(),
                NumberOfWishlistItems = numberOfWishlistItems.ToString(),
                RecentEvents          = recentEvents
            };

            var currentPlaythroughs = await playthroughDbService.GetUserCurrentPlaythroughsAsync(hoarderID);

            foreach (var pt in currentPlaythroughs)
            {
                userDashboardVM.CurrentGames.Add(UserDashboardMapper.ToGameViewModel(pt));
            }

            int finishedGamesTotal = 0;
            int playedGamesTotal   = 0;
            int unplayedGamesTotal = 0;
            int droppedGamesTotal  = 0;

            var platforms = await platformDbService.GetAllAsync();

            foreach (var platform in platforms)
            {
                int platformID           = platform.ID;
                var platformStatisticsVM = UserDashboardMapper.ToPlatformStatisticsViewModel(platform);

                int finishedGames = await playDataDbService.CountUserFinishedGamesByPlatformAsync(hoarderID, platformID);

                int playedGames = await playDataDbService.CountUserPlayedGamesByPlatformAsync(hoarderID, platformID);

                int unplayedGames = await playDataDbService.CountUserUnplayedGamesByPlatformAsync(hoarderID, platformID);

                int droppedGames = await playDataDbService.CountUserDroppedGamesByPlatformAsync(hoarderID, platformID);

                int totalGames = finishedGames + playedGames + unplayedGames + droppedGames;

                if (totalGames > 0)
                {
                    int finishedGamesPercentage = CalculatePercentage(totalGames, finishedGames);
                    int playedGamesPercentage   = CalculatePercentage(totalGames, playedGames);
                    int unplayedGamesPercentage = CalculatePercentage(totalGames, unplayedGames);
                    int droppedGamesPercentage  = CalculatePercentage(totalGames, droppedGames);

                    platformStatisticsVM.TotalGamesOwned         = totalGames.ToString();
                    platformStatisticsVM.FinishedGames           = finishedGames.ToString();
                    platformStatisticsVM.FinishedGamesPercentage = finishedGamesPercentage;
                    platformStatisticsVM.PlayedGames             = playedGames.ToString();
                    platformStatisticsVM.PlayedGamesPercentage   = playedGamesPercentage;
                    platformStatisticsVM.UnplayedGames           = unplayedGames.ToString();
                    platformStatisticsVM.UnplayedGamesPercentage = unplayedGamesPercentage;
                    platformStatisticsVM.DroppedGames            = droppedGames.ToString();
                    platformStatisticsVM.DroppedGamesPercentage  = droppedGamesPercentage;

                    userDashboardVM.PlatformStatistics.Add(platformStatisticsVM);

                    finishedGamesTotal += finishedGames;
                    playedGamesTotal   += playedGames;
                    unplayedGamesTotal += unplayedGames;
                    droppedGamesTotal  += droppedGames;
                }
            }

            int totalFinishedGamesPercentage = CalculatePercentage(numberOfOwnedGames, finishedGamesTotal);
            int totalPlayedGamesPercentage   = CalculatePercentage(numberOfOwnedGames, playedGamesTotal);
            int totalUnplayedGamesPercentage = CalculatePercentage(numberOfOwnedGames, unplayedGamesTotal);
            int totalDroppedGamesPercentage  = CalculatePercentage(numberOfOwnedGames, droppedGamesTotal);

            userDashboardVM.TotalGamesFinished           = finishedGamesTotal.ToString();
            userDashboardVM.TotalGamesFinishedPercentage = totalFinishedGamesPercentage;
            userDashboardVM.TotalGamesPlayed             = playedGamesTotal.ToString();
            userDashboardVM.TotalGamesPlayedPercentage   = totalPlayedGamesPercentage;
            userDashboardVM.TotalGamesUnplayed           = unplayedGamesTotal.ToString();
            userDashboardVM.TotalGamesUnplayedPercentage = totalUnplayedGamesPercentage;
            userDashboardVM.TotalGamesDropped            = droppedGamesTotal.ToString();
            userDashboardVM.TotalGamesDroppedPercentage  = totalDroppedGamesPercentage;

            return(userDashboardVM);
        }