本文整理汇总了C#中Rock.Model.BinaryFileService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFileService.Get方法的具体用法?C# BinaryFileService.Get怎么用?C# BinaryFileService.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.BinaryFileService
的用法示例。
在下文中一共展示了BinaryFileService.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes this instance.
/// </summary>
public void Execute()
{
using ( var rockContext = new RockContext() )
{
var binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( BinaryFileGuid );
if ( binaryFile != null )
{
string guidAsString = BinaryFileGuid.ToString();
// If any attribute still has this file as a default value, don't delete it
if ( new AttributeService( rockContext ).Queryable().Any( a => a.DefaultValue == guidAsString ) )
{
return;
}
// If any attribute value still has this file as a value, don't delete it
if ( new AttributeValueService( rockContext ).Queryable().Any( a => a.Value == guidAsString ) )
{
return;
}
binaryFileService.Delete( binaryFile );
rockContext.SaveChanges();
}
}
}
示例2: gBinaryFile_Delete
/// <summary>
/// Handles the Delete event of the gBinaryFile control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gBinaryFile_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = binaryFileService.Get( e.RowKeyId );
if ( binaryFile != null )
{
string errorMessage;
if ( !binaryFileService.CanDelete( binaryFile, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
Guid guid = binaryFile.Guid;
bool clearDeviceCache = binaryFile.BinaryFileType.Guid.Equals( Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL.AsGuid() );
binaryFileService.Delete( binaryFile );
rockContext.SaveChanges();
if ( clearDeviceCache )
{
Rock.CheckIn.KioskDevice.FlushAll();
Rock.CheckIn.KioskLabel.Flush( guid );
}
}
BindGrid();
}
示例3: Save
/// <summary>
/// Saves the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="personId">The person identifier.</param>
/// <returns></returns>
public override bool Save( FinancialTransactionImage item, int? personId )
{
// ensure that the BinaryFile.IsTemporary flag is set to false for any BinaryFiles that are associated with this record
BinaryFileService binaryFileService = new BinaryFileService( this.RockContext );
var binaryFile = binaryFileService.Get( item.BinaryFileId );
if ( binaryFile != null && binaryFile.IsTemporary )
{
binaryFile.IsTemporary = false;
}
return base.Save( item, personId );
}
示例4: gBinaryFile_Delete
/// <summary>
/// Handles the Delete event of the gBinaryFile control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gBinaryFile_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = binaryFileService.Get( e.RowKeyId );
if ( binaryFile != null )
{
string errorMessage;
if ( !binaryFileService.CanDelete( binaryFile, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
binaryFileService.Delete( binaryFile );
rockContext.SaveChanges();
}
BindGrid();
}
示例5: Send
/// <summary>
/// Sends the specified communication.
/// </summary>
/// <param name="communication">The communication.</param>
/// <exception cref="System.NotImplementedException"></exception>
public override void Send( Rock.Model.Communication communication )
{
using ( var rockContext = new RockContext() )
{
// Requery the Communication object
communication = new CommunicationService( rockContext )
.Queryable( "CreatedByPersonAlias.Person" )
.FirstOrDefault( c => c.Id == communication.Id );
if ( communication != null &&
communication.Status == Model.CommunicationStatus.Approved &&
communication.Recipients.Where( r => r.Status == Model.CommunicationRecipientStatus.Pending ).Any() &&
( !communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value.CompareTo( RockDateTime.Now ) <= 0 ) )
{
var currentPerson = communication.CreatedByPersonAlias.Person;
var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
var globalConfigValues = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( currentPerson );
// From - if none is set, use the one in the Organization's GlobalAttributes.
string fromAddress = communication.GetMediumDataValue( "FromAddress" );
if ( string.IsNullOrWhiteSpace( fromAddress ) )
{
fromAddress = globalAttributes.GetValue( "OrganizationEmail" );
}
string fromName = communication.GetMediumDataValue( "FromName" );
if ( string.IsNullOrWhiteSpace( fromName ) )
{
fromName = globalAttributes.GetValue( "OrganizationName" );
}
// Resolve any possible merge fields in the from address
fromAddress = fromAddress.ResolveMergeFields( globalConfigValues, currentPerson );
fromName = fromName.ResolveMergeFields( globalConfigValues, currentPerson );
MailMessage message = new MailMessage();
message.From = new MailAddress( fromAddress, fromName );
// Reply To
string replyTo = communication.GetMediumDataValue( "ReplyTo" );
if ( !string.IsNullOrWhiteSpace( replyTo ) )
{
message.ReplyToList.Add( new MailAddress( replyTo ) );
}
CheckSafeSender( message, globalAttributes );
// CC
string cc = communication.GetMediumDataValue( "CC" );
if ( !string.IsNullOrWhiteSpace( cc ) )
{
foreach ( string ccRecipient in cc.SplitDelimitedValues() )
{
message.CC.Add( new MailAddress( ccRecipient ) );
}
}
// BCC
string bcc = communication.GetMediumDataValue( "BCC" );
if ( !string.IsNullOrWhiteSpace( bcc ) )
{
foreach ( string bccRecipient in bcc.SplitDelimitedValues() )
{
message.Bcc.Add( new MailAddress( bccRecipient ) );
}
}
message.IsBodyHtml = true;
message.Priority = MailPriority.Normal;
using ( var smtpClient = GetSmtpClient() )
{
// Add Attachments
string attachmentIds = communication.GetMediumDataValue( "Attachments" );
if ( !string.IsNullOrWhiteSpace( attachmentIds ) )
{
var binaryFileService = new BinaryFileService( rockContext );
foreach ( string idVal in attachmentIds.SplitDelimitedValues() )
{
int binaryFileId = int.MinValue;
if ( int.TryParse( idVal, out binaryFileId ) )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
message.Attachments.Add( new Attachment( binaryFile.ContentStream, binaryFile.FileName ) );
}
}
}
}
var historyService = new HistoryService( rockContext );
var recipientService = new CommunicationRecipientService( rockContext );
//.........这里部分代码省略.........
示例6: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
Location location;
var rockContext = new RockContext();
LocationService locationService = new LocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
int locationId = int.Parse( hfLocationId.Value );
if ( locationId == 0 )
{
location = new Location();
location.Name = string.Empty;
}
else
{
location = locationService.Get( locationId );
FlushCampus( locationId );
}
int? orphanedImageId = null;
if ( location.ImageId != imgImage.BinaryFileId )
{
orphanedImageId = location.ImageId;
location.ImageId = imgImage.BinaryFileId;
}
location.Name = tbName.Text;
location.IsActive = cbIsActive.Checked;
location.LocationTypeValueId = ddlLocationType.SelectedValueAsId();
if ( gpParentLocation != null && gpParentLocation.Location != null )
{
location.ParentLocationId = gpParentLocation.Location.Id;
}
else
{
location.ParentLocationId = null;
}
location.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
acAddress.GetValues(location);
location.GeoPoint = geopPoint.SelectedValue;
if ( geopPoint.SelectedValue != null )
{
location.IsGeoPointLocked = true;
}
location.GeoFence = geopFence.SelectedValue;
location.IsGeoPointLocked = cbGeoPointLocked.Checked;
location.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributeEdits, location );
if ( !Page.IsValid )
{
return;
}
if ( !location.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.WrapTransaction( () =>
{
if ( location.Id.Equals( 0 ) )
{
locationService.Add( location );
}
rockContext.SaveChanges();
if (orphanedImageId.HasValue)
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( orphanedImageId.Value );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
rockContext.SaveChanges();
}
}
location.SaveAttributeValues( rockContext );
} );
var qryParams = new Dictionary<string, string>();
qryParams["LocationId"] = location.Id.ToString();
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
//.........这里部分代码省略.........
示例7: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="itemKey">The item key.</param>
/// <param name="itemKeyValue">The item key value.</param>
/// <param name="binaryFileTypeId">The binary file type id.</param>
public void ShowDetail( string itemKey, int itemKeyValue, int? binaryFileTypeId )
{
if ( !itemKey.Equals( "BinaryFileId" ) )
{
return;
}
var rockContext = new RockContext();
var binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = null;
if ( !itemKeyValue.Equals( 0 ) )
{
binaryFile = binaryFileService.Get( itemKeyValue );
}
if ( binaryFile != null )
{
lActionTitle.Text = ActionTitle.Edit( binaryFile.BinaryFileType.Name ).FormatAsHtmlTitle();
}
else
{
binaryFile = new BinaryFile { Id = 0, IsSystem = false, BinaryFileTypeId = binaryFileTypeId };
string friendlyName = BinaryFile.FriendlyTypeName;
if ( binaryFileTypeId.HasValue )
{
var binaryFileType = new BinaryFileTypeService( rockContext ).Get( binaryFileTypeId.Value );
if ( binaryFileType != null )
{
friendlyName = binaryFileType.Name;
}
}
lActionTitle.Text = ActionTitle.Add( friendlyName ).FormatAsHtmlTitle();
}
binaryFile.LoadAttributes( rockContext );
// initialize the fileUploader BinaryFileId to whatever file we are editing/viewing
fsFile.BinaryFileId = binaryFile.Id;
ShowBinaryFileDetail( binaryFile );
}
示例8: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
Category category;
using ( new UnitOfWorkScope() )
{
CategoryService categoryService = new CategoryService();
int categoryId = hfCategoryId.ValueAsInt();
if ( categoryId == 0 )
{
category = new Category();
category.IsSystem = false;
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
category.Order = 0;
}
else
{
category = categoryService.Get( categoryId );
}
category.Name = tbName.Text;
category.ParentCategoryId = cpParentCategory.SelectedValueAsInt();
category.IconCssClass = tbIconCssClass.Text;
List<int> orphanedBinaryFileIdList = new List<int>();
if ( !Page.IsValid )
{
return;
}
if ( !category.IsValid )
{
// Controls will render the error messages
return;
}
RockTransactionScope.WrapTransaction( () =>
{
if ( category.Id.Equals( 0 ) )
{
categoryService.Add( category, CurrentPersonId );
}
categoryService.Save( category, CurrentPersonId );
BinaryFileService binaryFileService = new BinaryFileService();
foreach (int binaryFileId in orphanedBinaryFileIdList)
{
var binaryFile = binaryFileService.Get(binaryFileId);
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
binaryFileService.Save( binaryFile, CurrentPersonId );
}
}
} );
}
var qryParams = new Dictionary<string, string>();
qryParams["CategoryId"] = category.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
示例9: Save
/// <summary>
/// Saves the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="personId">The person identifier.</param>
/// <returns></returns>
public override bool Save( Person item, int? personId )
{
// Set the nickname if a value was not entered
if ( string.IsNullOrWhiteSpace( item.NickName ) )
{
item.NickName = item.FirstName;
}
// ensure that the BinaryFile.IsTemporary flag is set to false for any BinaryFiles that are associated with this record
if ( item.PhotoId.HasValue )
{
BinaryFileService binaryFileService = new BinaryFileService( this.RockContext );
var binaryFile = binaryFileService.Get( item.PhotoId.Value );
if ( binaryFile != null && binaryFile.IsTemporary )
{
binaryFile.IsTemporary = false;
}
}
return base.Save( item, personId );
}
示例10: btnSave_Click
//.........这里部分代码省略.........
{
eventItem.EventItemAudiences.Remove( eventItemAudience );
eventItemAudienceService.Delete( eventItemAudience );
}
// Add or Update audiences from the UI
foreach ( int audienceId in AudiencesState )
{
EventItemAudience eventItemAudience = eventItem.EventItemAudiences.Where( a => a.DefinedValueId == audienceId ).FirstOrDefault();
if ( eventItemAudience == null )
{
eventItemAudience = new EventItemAudience();
eventItemAudience.DefinedValueId = audienceId;
eventItem.EventItemAudiences.Add( eventItemAudience );
}
}
// remove any calendar items that removed in the UI
var calendarIds = new List<int>();
calendarIds.AddRange( cblCalendars.SelectedValuesAsInt );
var uiCalendarGuids = ItemsState.Where( i => calendarIds.Contains( i.EventCalendarId ) ).Select( a => a.Guid );
foreach ( var eventCalendarItem in eventItem.EventCalendarItems.Where( a => !uiCalendarGuids.Contains( a.Guid ) ).ToList() )
{
// Make sure user is authorized to remove calendar (they may not have seen every calendar due to security)
if ( UserCanEdit || eventCalendarItem.EventCalendar.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
{
eventItem.EventCalendarItems.Remove( eventCalendarItem );
eventCalendarItemService.Delete( eventCalendarItem );
}
}
// Add or Update calendar items from the UI
foreach ( var calendar in ItemsState.Where( i => calendarIds.Contains( i.EventCalendarId ) ) )
{
var eventCalendarItem = eventItem.EventCalendarItems.Where( a => a.Guid == calendar.Guid ).FirstOrDefault();
if ( eventCalendarItem == null )
{
eventCalendarItem = new EventCalendarItem();
eventItem.EventCalendarItems.Add( eventCalendarItem );
}
eventCalendarItem.CopyPropertiesFrom( calendar );
}
if ( !eventItem.EventCalendarItems.Any() )
{
validationMessages.Add( "At least one calendar is required." );
}
if ( !Page.IsValid )
{
return;
}
if ( !eventItem.IsValid )
{
// Controls will render the error messages
return;
}
if ( validationMessages.Any() )
{
nbValidation.Text = "Please Correct the Following<ul><li>" + validationMessages.AsDelimited( "</li><li>" ) + "</li></ul>";
nbValidation.Visible = true;
return;
}
// use WrapTransaction since SaveAttributeValues does it's own RockContext.SaveChanges()
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
foreach ( EventCalendarItem eventCalendarItem in eventItem.EventCalendarItems )
{
eventCalendarItem.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, eventCalendarItem );
eventCalendarItem.SaveAttributeValues();
}
if ( orphanedImageId.HasValue )
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( orphanedImageId.Value );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
rockContext.SaveChanges();
}
}
} );
// Redirect back to same page so that item grid will show any attributes that were selected to show on grid
var qryParams = new Dictionary<string, string>();
if ( _calendarId.HasValue )
{
qryParams["EventCalendarId"] = _calendarId.Value.ToString();
}
qryParams["EventItemId"] = eventItem.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
}
示例11: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
BinaryFile binaryFile;
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
int? prevBinaryFileTypeId = null;
int binaryFileId = int.Parse( hfBinaryFileId.Value );
if ( binaryFileId == 0 )
{
binaryFile = new BinaryFile();
binaryFileService.Add( binaryFile );
}
else
{
binaryFile = binaryFileService.Get( binaryFileId );
prevBinaryFileTypeId = binaryFile != null ? binaryFile.BinaryFileTypeId : (int?)null;
}
// if a new file was uploaded, copy the uploaded file to this binaryFile (uploaded files are always new temporary binaryFiles)
if ( fsFile.BinaryFileId != binaryFile.Id)
{
var uploadedBinaryFile = binaryFileService.Get(fsFile.BinaryFileId ?? 0);
if (uploadedBinaryFile != null)
{
binaryFile.BinaryFileTypeId = uploadedBinaryFile.BinaryFileTypeId;
binaryFile.ContentStream = uploadedBinaryFile.ContentStream;
}
}
binaryFile.IsTemporary = false;
binaryFile.FileName = tbName.Text;
binaryFile.Description = tbDescription.Text;
binaryFile.MimeType = tbMimeType.Text;
binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
binaryFile.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFile );
if ( !Page.IsValid )
{
return;
}
if ( !binaryFile.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.WrapTransaction( () =>
{
foreach ( var id in OrphanedBinaryFileIdList )
{
var tempBinaryFile = binaryFileService.Get( id );
if ( tempBinaryFile != null && tempBinaryFile.IsTemporary )
{
binaryFileService.Delete( tempBinaryFile );
}
}
rockContext.SaveChanges();
binaryFile.SaveAttributeValues( rockContext );
} );
Rock.CheckIn.KioskLabel.Flush( binaryFile.Guid );
if ( !prevBinaryFileTypeId.Equals( binaryFile.BinaryFileTypeId ) )
{
var checkInBinaryFileType = new BinaryFileTypeService( rockContext )
.Get( Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL.AsGuid() );
if ( checkInBinaryFileType != null && (
( prevBinaryFileTypeId.HasValue && prevBinaryFileTypeId.Value == checkInBinaryFileType.Id ) ||
( binaryFile.BinaryFileTypeId.HasValue && binaryFile.BinaryFileTypeId.Value == checkInBinaryFileType.Id ) ) )
{
Rock.CheckIn.KioskDevice.FlushAll();
}
}
NavigateToParentPage();
}
示例12: fsFile_FileUploaded
/// <summary>
/// Handles the FileUploaded event of the fsFile control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void fsFile_FileUploaded( object sender, EventArgs e )
{
var rockContext = new RockContext();
var binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = null;
if ( fsFile.BinaryFileId.HasValue )
{
binaryFile = binaryFileService.Get( fsFile.BinaryFileId.Value );
}
if ( binaryFile != null )
{
if ( !string.IsNullOrWhiteSpace( tbName.Text ) )
{
binaryFile.FileName = tbName.Text;
}
// set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
binaryFile.Id = hfBinaryFileId.ValueAsInt();
binaryFile.Description = tbDescription.Text;
binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
if ( binaryFile.BinaryFileTypeId.HasValue )
{
binaryFile.BinaryFileType = new BinaryFileTypeService( rockContext ).Get( binaryFile.BinaryFileTypeId.Value );
}
var tempList = OrphanedBinaryFileIdList;
tempList.Add( fsFile.BinaryFileId.Value );
OrphanedBinaryFileIdList = tempList;
// load attributes, then get the attribute values from the UI
binaryFile.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFile );
// Process uploaded file using an optional workflow (which will probably populate attribute values)
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( GetAttributeValue( "Workflow" ), out workflowTypeGuid ) )
{
try
{
// temporarily set the binaryFile.Id to the uploaded binaryFile.Id so that workflow can do stuff with it
binaryFile.Id = fsFile.BinaryFileId ?? 0;
// create a rockContext for the workflow so that it can save it's changes, without
var workflowRockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService( workflowRockContext );
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Workflow.Activate( workflowType, binaryFile.FileName );
List<string> workflowErrors;
if ( new Rock.Model.WorkflowService( workflowRockContext ).Process( workflow, binaryFile, out workflowErrors ) )
{
binaryFile = binaryFileService.Get( binaryFile.Id );
}
}
}
finally
{
// set binaryFile.Id to original id again since the UploadedFile is a temporary binaryFile with a different id
binaryFile.Id = hfBinaryFileId.ValueAsInt();
}
}
ShowBinaryFileDetail( binaryFile );
}
}
示例13: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
BinaryFile binaryFile;
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
int binaryFileId = int.Parse( hfBinaryFileId.Value );
if ( binaryFileId == 0 )
{
binaryFile = new BinaryFile();
binaryFileService.Add( binaryFile );
}
else
{
binaryFile = binaryFileService.Get( binaryFileId );
}
// if a new file was uploaded, copy the uploaded file to this binaryFile (uploaded files are always new temporary binaryFiles)
if ( fsFile.BinaryFileId != binaryFile.Id)
{
var uploadedBinaryFile = binaryFileService.Get(fsFile.BinaryFileId ?? 0);
if (uploadedBinaryFile != null)
{
binaryFile.BinaryFileTypeId = uploadedBinaryFile.BinaryFileTypeId;
binaryFile.ContentStream = uploadedBinaryFile.ContentStream;
}
}
binaryFile.IsTemporary = false;
binaryFile.FileName = tbName.Text;
binaryFile.Description = tbDescription.Text;
binaryFile.MimeType = tbMimeType.Text;
binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
binaryFile.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFile );
if ( !Page.IsValid )
{
return;
}
if ( !binaryFile.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.WrapTransaction( () =>
{
foreach ( var id in OrphanedBinaryFileIdList )
{
var tempBinaryFile = binaryFileService.Get( id );
if ( tempBinaryFile != null && tempBinaryFile.IsTemporary )
{
binaryFileService.Delete( tempBinaryFile );
}
}
rockContext.SaveChanges();
binaryFile.SaveAttributeValues( rockContext );
} );
NavigateToParentPage();
}
示例14: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
Location location = null;
var rockContext = new RockContext();
LocationService locationService = new LocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
int locationId = int.Parse( hfLocationId.Value );
if ( locationId != 0 )
{
location = locationService.Get( locationId );
FlushCampus( locationId );
}
if ( location == null )
{
location = new Location();
location.Name = string.Empty;
}
string previousName = location.Name;
int? orphanedImageId = null;
if ( location.ImageId != imgImage.BinaryFileId )
{
orphanedImageId = location.ImageId;
location.ImageId = imgImage.BinaryFileId;
}
location.Name = tbName.Text;
location.IsActive = cbIsActive.Checked;
location.LocationTypeValueId = ddlLocationType.SelectedValueAsId();
if ( gpParentLocation != null && gpParentLocation.Location != null )
{
location.ParentLocationId = gpParentLocation.Location.Id;
}
else
{
location.ParentLocationId = null;
}
location.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
acAddress.GetValues(location);
location.GeoPoint = geopPoint.SelectedValue;
if ( geopPoint.SelectedValue != null )
{
location.IsGeoPointLocked = true;
}
location.GeoFence = geopFence.SelectedValue;
location.IsGeoPointLocked = cbGeoPointLocked.Checked;
location.SoftRoomThreshold = nbSoftThreshold.Text.AsIntegerOrNull();
location.FirmRoomThreshold = nbFirmThreshold.Text.AsIntegerOrNull();
location.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributeEdits, location );
if ( !Page.IsValid )
{
return;
}
// if the location IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of location didn't pass.
// So, make sure a message is displayed in the validation summary
cvLocation.IsValid = location.IsValid;
if ( !cvLocation.IsValid )
{
cvLocation.ErrorMessage = location.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
rockContext.WrapTransaction( () =>
{
if ( location.Id.Equals( 0 ) )
{
locationService.Add( location );
}
rockContext.SaveChanges();
if (orphanedImageId.HasValue)
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( orphanedImageId.Value );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
rockContext.SaveChanges();
//.........这里部分代码省略.........
示例15: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
Category category;
var rockContext = new RockContext();
CategoryService categoryService = new CategoryService( rockContext );
int categoryId = hfCategoryId.ValueAsInt();
if ( categoryId == 0 )
{
category = new Category();
category.IsSystem = false;
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
category.Order = 0;
categoryService.Add( category );
}
else
{
category = categoryService.Get( categoryId );
}
category.Name = tbName.Text;
category.ParentCategoryId = cpParentCategory.SelectedValueAsInt();
category.IconCssClass = tbIconCssClass.Text;
category.HighlightColor = tbHighlightColor.Text;
List<int> orphanedBinaryFileIdList = new List<int>();
if ( !Page.IsValid )
{
return;
}
if ( !category.IsValid )
{
// Controls will render the error messages
return;
}
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
foreach ( int binaryFileId in orphanedBinaryFileIdList )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
}
}
rockContext.SaveChanges();
CategoryCache.Flush( category.Id );
var qryParams = new Dictionary<string, string>();
qryParams["CategoryId"] = category.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}