public virtual Distributor UpdateDistributor(Distributor entity) { if (entity.IsTransient()) { return(entity); } Distributor other = GetDistributor(entity.DistributorId); if (entity.Equals(other)) { return(entity); } string sql = @"Update Distributor set [DistributorGUID]=@DistributorGUID , [Name]=@Name , [SEName]=@SEName , [SEKeywords]=@SEKeywords , [SEDescription]=@SEDescription , [SETitle]=@SETitle , [SENoScript]=@SENoScript , [SEAltText]=@SEAltText , [Address1]=@Address1 , [Address2]=@Address2 , [Suite]=@Suite , [City]=@City , [State]=@State , [ZipCode]=@ZipCode , [Country]=@Country , [Phone]=@Phone , [FAX]=@FAX , [URL]=@URL , [Email]=@Email , [Summary]=@Summary , [Description]=@Description , [Notes]=@Notes , [QuantityDiscountID]=@QuantityDiscountID , [SortByLooks]=@SortByLooks , [XmlPackage]=@XmlPackage , [ColWidth]=@ColWidth , [DisplayOrder]=@DisplayOrder , [ExtensionData]=@ExtensionData , [ContentsBGColor]=@ContentsBGColor , [PageBGColor]=@PageBGColor , [GraphicsColor]=@GraphicsColor , [NotificationXmlPackage]=@NotificationXmlPackage , [ImageFilenameOverride]=@ImageFilenameOverride , [ParentDistributorID]=@ParentDistributorID , [Published]=@Published , [Wholesale]=@Wholesale , [IsImport]=@IsImport , [Deleted]=@Deleted , [CreatedOn]=@CreatedOn , [PageSize]=@PageSize , [TaxClassID]=@TaxClassID , [SkinID]=@SkinID , [TemplateName]=@TemplateName where DistributorID=@DistributorID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@DistributorID", entity.DistributorId) , new SqlParameter("@DistributorGUID", entity.DistributorGuid) , new SqlParameter("@Name", entity.Name) , new SqlParameter("@SEName", entity.SeName ?? (object)DBNull.Value) , new SqlParameter("@SEKeywords", entity.SeKeywords ?? (object)DBNull.Value) , new SqlParameter("@SEDescription", entity.SeDescription ?? (object)DBNull.Value) , new SqlParameter("@SETitle", entity.SeTitle ?? (object)DBNull.Value) , new SqlParameter("@SENoScript", entity.SeNoScript ?? (object)DBNull.Value) , new SqlParameter("@SEAltText", entity.SeAltText ?? (object)DBNull.Value) , new SqlParameter("@Address1", entity.Address1 ?? (object)DBNull.Value) , new SqlParameter("@Address2", entity.Address2 ?? (object)DBNull.Value) , new SqlParameter("@Suite", entity.Suite ?? (object)DBNull.Value) , new SqlParameter("@City", entity.City ?? (object)DBNull.Value) , new SqlParameter("@State", entity.State ?? (object)DBNull.Value) , new SqlParameter("@ZipCode", entity.ZipCode ?? (object)DBNull.Value) , new SqlParameter("@Country", entity.Country ?? (object)DBNull.Value) , new SqlParameter("@Phone", entity.Phone ?? (object)DBNull.Value) , new SqlParameter("@FAX", entity.Fax ?? (object)DBNull.Value) , new SqlParameter("@URL", entity.Url ?? (object)DBNull.Value) , new SqlParameter("@Email", entity.Email ?? (object)DBNull.Value) , new SqlParameter("@Summary", entity.Summary ?? (object)DBNull.Value) , new SqlParameter("@Description", entity.Description ?? (object)DBNull.Value) , new SqlParameter("@Notes", entity.Notes ?? (object)DBNull.Value) , new SqlParameter("@QuantityDiscountID", entity.QuantityDiscountId ?? (object)DBNull.Value) , new SqlParameter("@SortByLooks", entity.SortByLooks) , new SqlParameter("@XmlPackage", entity.XmlPackage ?? (object)DBNull.Value) , new SqlParameter("@ColWidth", entity.ColWidth) , new SqlParameter("@DisplayOrder", entity.DisplayOrder) , new SqlParameter("@ExtensionData", entity.ExtensionData ?? (object)DBNull.Value) , new SqlParameter("@ContentsBGColor", entity.ContentsBgColor ?? (object)DBNull.Value) , new SqlParameter("@PageBGColor", entity.PageBgColor ?? (object)DBNull.Value) , new SqlParameter("@GraphicsColor", entity.GraphicsColor ?? (object)DBNull.Value) , new SqlParameter("@NotificationXmlPackage", entity.NotificationXmlPackage ?? (object)DBNull.Value) , new SqlParameter("@ImageFilenameOverride", entity.ImageFilenameOverride ?? (object)DBNull.Value) , new SqlParameter("@ParentDistributorID", entity.ParentDistributorId) , new SqlParameter("@Published", entity.Published) , new SqlParameter("@Wholesale", entity.Wholesale) , new SqlParameter("@IsImport", entity.IsImport) , new SqlParameter("@Deleted", entity.Deleted) , new SqlParameter("@CreatedOn", entity.CreatedOn) , new SqlParameter("@PageSize", entity.PageSize) , new SqlParameter("@TaxClassID", entity.TaxClassId) , new SqlParameter("@SkinID", entity.SkinId) , new SqlParameter("@TemplateName", entity.TemplateName) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetDistributor(entity.DistributorId)); }
public virtual Distributor InsertDistributor(Distributor entity) { Distributor other = new Distributor(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into Distributor ( [DistributorGUID] ,[Name] ,[SEName] ,[SEKeywords] ,[SEDescription] ,[SETitle] ,[SENoScript] ,[SEAltText] ,[Address1] ,[Address2] ,[Suite] ,[City] ,[State] ,[ZipCode] ,[Country] ,[Phone] ,[FAX] ,[URL] ,[Email] ,[Summary] ,[Description] ,[Notes] ,[QuantityDiscountID] ,[SortByLooks] ,[XmlPackage] ,[ColWidth] ,[DisplayOrder] ,[ExtensionData] ,[ContentsBGColor] ,[PageBGColor] ,[GraphicsColor] ,[NotificationXmlPackage] ,[ImageFilenameOverride] ,[ParentDistributorID] ,[Published] ,[Wholesale] ,[IsImport] ,[Deleted] ,[CreatedOn] ,[PageSize] ,[TaxClassID] ,[SkinID] ,[TemplateName] ) Values ( @DistributorGUID , @Name , @SEName , @SEKeywords , @SEDescription , @SETitle , @SENoScript , @SEAltText , @Address1 , @Address2 , @Suite , @City , @State , @ZipCode , @Country , @Phone , @FAX , @URL , @Email , @Summary , @Description , @Notes , @QuantityDiscountID , @SortByLooks , @XmlPackage , @ColWidth , @DisplayOrder , @ExtensionData , @ContentsBGColor , @PageBGColor , @GraphicsColor , @NotificationXmlPackage , @ImageFilenameOverride , @ParentDistributorID , @Published , @Wholesale , @IsImport , @Deleted , @CreatedOn , @PageSize , @TaxClassID , @SkinID , @TemplateName ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@DistributorID", entity.DistributorId) , new SqlParameter("@DistributorGUID", entity.DistributorGuid) , new SqlParameter("@Name", entity.Name) , new SqlParameter("@SEName", entity.SeName ?? (object)DBNull.Value) , new SqlParameter("@SEKeywords", entity.SeKeywords ?? (object)DBNull.Value) , new SqlParameter("@SEDescription", entity.SeDescription ?? (object)DBNull.Value) , new SqlParameter("@SETitle", entity.SeTitle ?? (object)DBNull.Value) , new SqlParameter("@SENoScript", entity.SeNoScript ?? (object)DBNull.Value) , new SqlParameter("@SEAltText", entity.SeAltText ?? (object)DBNull.Value) , new SqlParameter("@Address1", entity.Address1 ?? (object)DBNull.Value) , new SqlParameter("@Address2", entity.Address2 ?? (object)DBNull.Value) , new SqlParameter("@Suite", entity.Suite ?? (object)DBNull.Value) , new SqlParameter("@City", entity.City ?? (object)DBNull.Value) , new SqlParameter("@State", entity.State ?? (object)DBNull.Value) , new SqlParameter("@ZipCode", entity.ZipCode ?? (object)DBNull.Value) , new SqlParameter("@Country", entity.Country ?? (object)DBNull.Value) , new SqlParameter("@Phone", entity.Phone ?? (object)DBNull.Value) , new SqlParameter("@FAX", entity.Fax ?? (object)DBNull.Value) , new SqlParameter("@URL", entity.Url ?? (object)DBNull.Value) , new SqlParameter("@Email", entity.Email ?? (object)DBNull.Value) , new SqlParameter("@Summary", entity.Summary ?? (object)DBNull.Value) , new SqlParameter("@Description", entity.Description ?? (object)DBNull.Value) , new SqlParameter("@Notes", entity.Notes ?? (object)DBNull.Value) , new SqlParameter("@QuantityDiscountID", entity.QuantityDiscountId ?? (object)DBNull.Value) , new SqlParameter("@SortByLooks", entity.SortByLooks) , new SqlParameter("@XmlPackage", entity.XmlPackage ?? (object)DBNull.Value) , new SqlParameter("@ColWidth", entity.ColWidth) , new SqlParameter("@DisplayOrder", entity.DisplayOrder) , new SqlParameter("@ExtensionData", entity.ExtensionData ?? (object)DBNull.Value) , new SqlParameter("@ContentsBGColor", entity.ContentsBgColor ?? (object)DBNull.Value) , new SqlParameter("@PageBGColor", entity.PageBgColor ?? (object)DBNull.Value) , new SqlParameter("@GraphicsColor", entity.GraphicsColor ?? (object)DBNull.Value) , new SqlParameter("@NotificationXmlPackage", entity.NotificationXmlPackage ?? (object)DBNull.Value) , new SqlParameter("@ImageFilenameOverride", entity.ImageFilenameOverride ?? (object)DBNull.Value) , new SqlParameter("@ParentDistributorID", entity.ParentDistributorId) , new SqlParameter("@Published", entity.Published) , new SqlParameter("@Wholesale", entity.Wholesale) , new SqlParameter("@IsImport", entity.IsImport) , new SqlParameter("@Deleted", entity.Deleted) , new SqlParameter("@CreatedOn", entity.CreatedOn) , new SqlParameter("@PageSize", entity.PageSize) , new SqlParameter("@TaxClassID", entity.TaxClassId) , new SqlParameter("@SkinID", entity.SkinId) , new SqlParameter("@TemplateName", entity.TemplateName) }; 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(GetDistributor(Convert.ToInt32(identity))); } return(entity); }