Ejemplo n.º 1
0
        public static async Task <bool> InsertAward(AwardType type, int userId, int?gameId, string version, string versionData)
        {
            try
            {
                AddAwardResult result = null;
                Log.Message(LogLevel.Info, "[InsertAward] - Inserting award...");
                using (var connection = DataContextFactory.CreateConnection())
                {
                    result = await connection.QueryFirstOrDefaultAsync <AddAwardResult>(StoredProcedure.Award_AddAwardHistory, new
                    {
                        GameId      = gameId,
                        UserId      = userId,
                        Type        = type,
                        Version     = version,
                        VersionData = versionData
                    }, commandType : System.Data.CommandType.StoredProcedure);
                }

                if (!string.IsNullOrEmpty(result.Error))
                {
                    Log.Message(LogLevel.Error, $"[ProcessAwards] - Error inserting award, Error: {result.Error}");
                    return(false);
                }

                await PixelHubClient.NotifyAward(new AwardNotification
                {
                    AwardId  = result.AwardId,
                    Level    = result.AwardLevel,
                    Name     = result.AwardName,
                    Points   = result.AwardPoints,
                    UserId   = result.UserId,
                    UserName = result.UserName
                });

                await PixelHubClient.NotifyPoints(new PointsNotification
                {
                    UserId = result.UserId,
                    Points = result.UserPoints
                });

                Log.Message(LogLevel.Info, "[InsertAward] - Inserting award complete.");
                return(true);
            }
            catch (Exception ex)
            {
                Log.Message(LogLevel.Error, $"[ProcessAwards] - Exception inserting award, Error: {ex.Message}");
            }
            return(false);
        }