public virtual ProductCustomerLevel UpdateProductCustomerLevel(ProductCustomerLevel entity) { if (entity.IsTransient()) { return(entity); } ProductCustomerLevel other = GetProductCustomerLevel(entity.ProductId); if (entity.Equals(other)) { return(entity); } string sql = @"Update ProductCustomerLevel set [CustomerLevelID]=@CustomerLevelID , [DisplayOrder]=@DisplayOrder , [CreatedOn]=@CreatedOn where ProductID=@ProductID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@ProductID", entity.ProductId) , new SqlParameter("@CustomerLevelID", entity.CustomerLevelId) , new SqlParameter("@DisplayOrder", entity.DisplayOrder) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetProductCustomerLevel(entity.ProductId)); }
public virtual ProductCustomerLevel InsertProductCustomerLevel(ProductCustomerLevel entity) { ProductCustomerLevel other = new ProductCustomerLevel(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into ProductCustomerLevel ( [ProductID] ,[CustomerLevelID] ,[DisplayOrder] ,[CreatedOn] ) Values ( @ProductID , @CustomerLevelID , @DisplayOrder , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@ProductID", entity.ProductId) , new SqlParameter("@CustomerLevelID", entity.CustomerLevelId) , new SqlParameter("@DisplayOrder", entity.DisplayOrder) , 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(GetProductCustomerLevel(Convert.ToInt32(identity))); } return(entity); }