public Models.SiegeGuilda InserirSiegeGuilda(Models.SiegeGuilda obj) { SqlConnection conexao = new SqlConnection(); SqlCommand command = new SqlCommand(); conexao.ConnectionString = BLO.Conexao.ObterStringConexao2(); StringBuilder select = new StringBuilder(); select.AppendLine("SET DATEFORMAT dmy;"); select.Append("MERGE DBO.SiegeGuilda AS TARGET "); select.Append("USING(SELECT @IdSiege AS IdSiege, @IdGuilda as IdGuilda) AS SOURCE "); select.Append("ON TARGET.IdSiege = SOURCE.IdSiege and "); select.Append("Target.IdGuilda = SOURCE.IdGuilda "); select.Append("WHEN MATCHED THEN "); select.Append("UPDATE SET TARGET.Posicao = @Posicao, Rating = @Rating, MatchScore = @MatchScore, Members = @Members "); select.Append("WHEN NOT MATCHED BY TARGET THEN "); select.Append("INSERT(IdSiege, IdGuilda, Posicao,Rating,MatchScore,Members) "); select.Append("VALUES(@IdSiege, @IdGuilda, @Posicao,@Rating,@MatchScore,@Members); "); command.Parameters.Add(new SqlParameter("@IdSiege", System.Data.SqlDbType.BigInt)); command.Parameters["@IdSiege"].Value = obj.IdSiege; command.Parameters.Add(new SqlParameter("@IdGuilda", System.Data.SqlDbType.BigInt)); command.Parameters["@IdGuilda"].Value = obj.IdGuilda; command.Parameters.Add(new SqlParameter("@Posicao", System.Data.SqlDbType.Int)); command.Parameters["@Posicao"].Value = obj.Posicao; command.Parameters.Add(new SqlParameter("@Rating", System.Data.SqlDbType.Int)); command.Parameters["@Rating"].Value = obj.Rating; command.Parameters.Add(new SqlParameter("@MatchScore", System.Data.SqlDbType.Float)); command.Parameters["@MatchScore"].Value = obj.MatchScore; command.Parameters.Add(new SqlParameter("@Members", System.Data.SqlDbType.Int)); command.Parameters["@Members"].Value = obj.Members; command.CommandText = select.ToString(); command.CommandType = System.Data.CommandType.Text; conexao.Open(); command.Connection = conexao; command.ExecuteNonQuery(); conexao.Close(); conexao.Dispose(); return(obj); }
public Models.SiegeGuilda InserirSiegeGuilda(Models.SiegeGuilda obj) { return(new DAO.DAO_Siege().InserirSiegeGuilda(obj)); }