public bool Update(AddCounterCommand counterToUpdate, string id)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                var sql = @"UPDATE [dbo].[Counter]
                               SET [Id] = @newId
                                  ,[OpponentTeamId] = @opponentTeamId
                                  ,[CounterTeamId] = @counterTeamId
                                  ,[IsHardCounter] = @isHardCounter
                                  ,[BattleType] = @battleType
                                  ,[Description] = @description
                                  ,[VideoUrl] = @videoUrl
                             WHERE [Id] = @id";

                var parameters = new
                {
                    id,
                    newId          = $"{counterToUpdate.OpponentTeamId}-v-{counterToUpdate.CounterTeamId}",
                    opponentTeamId = counterToUpdate.OpponentTeamId,
                    counterTeamId  = counterToUpdate.CounterTeamId,
                    isHardCounter  = counterToUpdate.IsHardCounter,
                    battleType     = counterToUpdate.BattleType,
                    description    = counterToUpdate.Description,
                    videoUrl       = counterToUpdate.VideoUrl
                };

                return(connection.Execute(sql, parameters) == 1);
            }
        }
        public bool Create(AddCounterCommand newCounter)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                var addCounter = @"INSERT INTO [dbo].[Counter]
                                                   ([Id]
                                                   ,[OpponentTeamId]
                                                   ,[CounterTeamId]
                                                   ,[IsHardCounter]
                                                   ,[BattleType]
                                                   ,[Description]
                                                   ,[VideoUrl])
                                             VALUES
                                                   (@id
                                                   ,@opponentTeamId
                                                   ,@counterTeamId
                                                   ,@isHardCounter
                                                   ,@battleType
                                                   ,@description
                                                   ,@videoUrl)";

                var parameters = new
                {
                    id             = $"{newCounter.OpponentTeamId}-v-{newCounter.CounterTeamId}",
                    opponentTeamId = newCounter.OpponentTeamId,
                    counterTeamId  = newCounter.CounterTeamId,
                    isHardCounter  = newCounter.IsHardCounter,
                    battleType     = newCounter.BattleType,
                    description    = newCounter.Description,
                    videoUrl       = newCounter.VideoUrl
                };

                var rowsAffected = connection.Execute(addCounter, parameters);

                return(rowsAffected == 1);
            }
        }
예제 #3
0
 public bool PutCounter(AddCounterCommand counter, string counterId)
 {
     return(_repo.Update(counter, counterId));
 }
예제 #4
0
 public bool PostCounter(AddCounterCommand counter)
 {
     return(_repo.Create(counter));
 }