public virtual CountryTaxRate UpdateCountryTaxRate(CountryTaxRate entity) { if (entity.IsTransient()) { return(entity); } CountryTaxRate other = GetCountryTaxRate(entity.CountryTaxId); if (entity.Equals(other)) { return(entity); } string sql = @"Update CountryTaxRate set [CountryID]=@CountryID , [TaxClassID]=@TaxClassID , [TaxRate]=@TaxRate , [CreatedOn]=@CreatedOn where CountryTaxID=@CountryTaxID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@CountryTaxID", entity.CountryTaxId) , new SqlParameter("@CountryID", entity.CountryId) , new SqlParameter("@TaxClassID", entity.TaxClassId) , new SqlParameter("@TaxRate", entity.TaxRate ?? (object)DBNull.Value) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetCountryTaxRate(entity.CountryTaxId)); }
public virtual CountryTaxRate InsertCountryTaxRate(CountryTaxRate entity) { CountryTaxRate other = new CountryTaxRate(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into CountryTaxRate ( [CountryID] ,[TaxClassID] ,[TaxRate] ,[CreatedOn] ) Values ( @CountryID , @TaxClassID , @TaxRate , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@CountryTaxID", entity.CountryTaxId) , new SqlParameter("@CountryID", entity.CountryId) , new SqlParameter("@TaxClassID", entity.TaxClassId) , new SqlParameter("@TaxRate", entity.TaxRate ?? (object)DBNull.Value) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray); if (identity == DBNull.Value) { throw new DataException("Identity column was null as a result of the insert operation."); } return(GetCountryTaxRate(Convert.ToInt32(identity))); } return(entity); }