Ejemplo n.º 1
0
        public async Task <GenericResponse <Gw2StatsResponse> > GetGw2StatsFromCache(string gameUsername)
        {
            TGw2Stat dbStats = _databaseContext.TGw2Stat.FirstOrDefault(s => s.UserGame.Username == gameUsername);

            if (dbStats == null)
            {
                return(new GenericResponse <Gw2StatsResponse>($"Cannot get stats for {gameUsername}", null));
            }

            return(new GenericResponse <Gw2StatsResponse>(dbStats.ConvertToGw2StatsResponse()));
        }
Ejemplo n.º 2
0
 public static Gw2StatsResponse ConvertToGw2StatsResponse(this TGw2Stat dbStats)
 {
     return(new Gw2StatsResponse
     {
         Aggregate = new Gw2StatsResponseAggregate
         {
             Byes = dbStats.Byes,
             Desertions = dbStats.Desertions,
             Forfeits = dbStats.Forfeits,
             Losses = dbStats.Losses,
             Wins = dbStats.Wins
         },
         PvpRank = dbStats.PvpRank,
         PvpRankPoint = dbStats.PvpRankPoints,
         PvpRankRollovers = dbStats.PvpRankRollovers
     });
 }
Ejemplo n.º 3
0
        public async Task <GenericResponse <BooleanResponse> > UpdateCache(Gw2StatsResponse gw2StatResponse, TUserGame userGame)
        {
            TGw2Stat dbStats = _databaseContext.TGw2Stat.FirstOrDefault(s => s.UserGame.Username == userGame.Username);

            bool newStats = false;

            if (dbStats == null)
            {
                newStats = true;
                dbStats  = new TGw2Stat {
                    UserGameId = userGame.Id
                };
            }

            dbStats.PvpRank          = gw2StatResponse.PvpRank;
            dbStats.PvpRankPoints    = gw2StatResponse.PvpRankPoint;
            dbStats.PvpRankRollovers = gw2StatResponse.PvpRankRollovers;
            dbStats.Wins             = gw2StatResponse.Aggregate.Wins;
            dbStats.Losses           = gw2StatResponse.Aggregate.Losses;
            dbStats.Desertions       = gw2StatResponse.Aggregate.Desertions;
            dbStats.Byes             = gw2StatResponse.Aggregate.Byes;
            dbStats.Forfeits         = gw2StatResponse.Aggregate.Forfeits;
            dbStats.UserGameId       = userGame.Id;

            try
            {
                if (newStats)
                {
                    _databaseContext.TGw2Stat.Add(dbStats);
                }
                else
                {
                    _databaseContext.TGw2Stat.Update(dbStats);
                }
                await _databaseContext.SaveChangesAsync();

                return(new GenericResponse <BooleanResponse>(new BooleanResponse {
                    Success = true
                }));
            }
            catch (DbUpdateException e)
            {
                return(new GenericResponse <BooleanResponse>("Error while saving in cache", e));
            }
        }
Ejemplo n.º 4
0
        public async Task <GenericResponse <BooleanResponse> > DeleteCache(long userId)
        {
            try
            {
                // Get
                TGw2Stat cache = _databaseContext.TGw2Stat.Where(s => s.UserGame.UserId == userId).FirstOrDefault();

                // Delete if found
                if (cache != null)
                {
                    _databaseContext.TGw2Stat.Remove(cache);
                    await _databaseContext.SaveChangesAsync();
                }
                return(new GenericResponse <BooleanResponse>(new BooleanResponse {
                    Success = true
                }));
            }
            catch (DbUpdateException e)
            {
                return(new GenericResponse <BooleanResponse>("Error while deleting game cache", e));
            }
        }