public CTI<CharacterProfileResponseItem> GetProfile(int? userID) {
            try {
                var selectedUserID = userID ?? _authorizedUser.ID;

                using (var db = new GameMetricContext()) {
                    var result = new CharacterProfileResponseItem {
                        GameHistory = db.GameListingViews.Where(a => a.UserID == selectedUserID).ToList()
                    };

                    result.Character = db.CharacterViews.Where(a => a.UserID == selectedUserID).ToList().FirstOrDefault();

                    return new CTI<CharacterProfileResponseItem>(result);
                }
            } catch (Exception ex) {
                return new CTI<CharacterProfileResponseItem>(null, ex.ToString());
            }
        }
Esempio n. 2
0
        public async Task<CTI<bool>> AddMetric(PlayerCharacterGames gameMetric) {
            try {
                using (var db = new GameMetricContext()) {
                    gameMetric.UserID = _authorizedUser.ID;
                    gameMetric.PlayerCharacterID = _authorizedUser.CharacterID;
                    gameMetric.Modified = DateTime.UtcNow;
                    gameMetric.Created = DateTime.UtcNow;
                    gameMetric.Active = true;

                    db.Games.Add(gameMetric);

                    var result = await db.SaveChangesAsync();

                    return new CTI<bool>(result > 0);
                }
            } catch (Exception ex) {
                return new CTI<bool>(false, ex.ToString());
            }
        }