public Models.SiegePlayerOponente InserirSiegePlayerOponente(Models.SiegePlayerOponente obj) { SqlConnection conexao = new SqlConnection(); SqlCommand command = new SqlCommand(); conexao.ConnectionString = BLO.Conexao.ObterStringConexao2(); StringBuilder select = new StringBuilder(); select.AppendLine("SET DATEFORMAT dmy;"); select.AppendLine("MERGE DBO.SiegePlayerOponente AS TARGET "); select.AppendLine("USING(SELECT @IdSiege AS IdSiege, @IdPlayer as IdPlayer, @IdGuilda as IdGuild) AS SOURCE "); select.AppendLine("ON TARGET.IdSiege = SOURCE.IdSiege and "); select.AppendLine("Target.IdPlayer = SOURCE.IdPlayer and "); select.AppendLine("Target.IdGuilda = SOURCE.IdGuild "); select.AppendLine("WHEN MATCHED THEN "); select.AppendLine("UPDATE SET TARGET.Nome = @Nome "); select.AppendLine("WHEN NOT MATCHED BY TARGET THEN "); select.AppendLine("INSERT(IdPlayer, IdSiege, IdGuilda, Nome) "); select.AppendLine("VALUES(@IdPlayer, @IdSiege, @IdGuilda, @Nome)"); select.AppendLine("OUTPUT inserted.Id ;"); command.Parameters.Add(new SqlParameter("@IdSiege", System.Data.SqlDbType.BigInt)); command.Parameters["@IdSiege"].Value = obj.IdSiege; command.Parameters.Add(new SqlParameter("@IdPlayer", System.Data.SqlDbType.BigInt)); command.Parameters["@IdPlayer"].Value = obj.IdPlayer; command.Parameters.Add(new SqlParameter("@IdGuilda", System.Data.SqlDbType.BigInt)); command.Parameters["@IdGuilda"].Value = obj.IdGuild; command.Parameters.Add(new SqlParameter("@Nome", System.Data.SqlDbType.VarChar)); command.Parameters["@Nome"].Value = obj.Nome; command.CommandText = select.ToString(); command.CommandType = System.Data.CommandType.Text; conexao.Open(); command.Connection = conexao; long modified = (long)command.ExecuteScalar(); conexao.Close(); conexao.Dispose(); obj.Id = modified; return(obj); }
public Models.SiegePlayerOponente InserirSiegePlayerOponente(Models.SiegePlayerOponente obj) { return(new DAO.DAO_SiegePlayer().InserirSiegePlayerOponente(obj)); }