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