/// <summary> /// Handles the FileRemoved event of the fileUpDoc control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="FileUploaderEventArgs"/> instance containing the event data.</param> protected void fileUpDoc_FileRemoved(object sender, FileUploaderEventArgs e) { var fileUpDoc = (Rock.Web.UI.Controls.FileUploader)sender; if (e.BinaryFileId.HasValue) { DocumentsState.Remove(e.BinaryFileId.Value); BindDocuments(true); } }
/// <summary> /// Binds the documents. /// </summary> /// <param name="canEdit">if set to <c>true</c> [can edit].</param> private void BindDocuments(bool canEdit) { var ds = DocumentsState.ToList(); if (ds.Count() < 6) { ds.Add(0); } dlDocuments.DataSource = ds; dlDocuments.DataBind(); }
public ImagesViewHelper(DocumentsState state) { this.state = state; }
public PluginHelper(DocumentsState state) { this.state = state; }
/// <summary> /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e) { if (Page.IsValid) { RockContext rockContext = new RockContext(); BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService(rockContext); BenevolenceResultService benevolenceResultService = new BenevolenceResultService(rockContext); BenevolenceRequest benevolenceRequest = null; int benevolenceRequestId = PageParameter("BenevolenceRequestId").AsInteger(); if (!benevolenceRequestId.Equals(0)) { benevolenceRequest = benevolenceRequestService.Get(benevolenceRequestId); } if (benevolenceRequest == null) { benevolenceRequest = new BenevolenceRequest { Id = 0 }; } benevolenceRequest.FirstName = dtbFirstName.Text; benevolenceRequest.LastName = dtbLastName.Text; benevolenceRequest.Email = ebEmail.Text; benevolenceRequest.RequestText = dtbRequestText.Text; benevolenceRequest.ResultSummary = dtbSummary.Text; benevolenceRequest.CampusId = cpCampus.SelectedCampusId; benevolenceRequest.ProvidedNextSteps = dtbProvidedNextSteps.Text; benevolenceRequest.GovernmentId = dtbGovernmentId.Text; if (lapAddress.Location != null) { benevolenceRequest.LocationId = lapAddress.Location.Id; } benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId; benevolenceRequest.CaseWorkerPersonAliasId = ddlCaseWorker.SelectedValue.AsIntegerOrNull(); benevolenceRequest.RequestStatusValueId = ddlRequestStatus.SelectedValue.AsIntegerOrNull(); benevolenceRequest.ConnectionStatusValueId = ddlConnectionStatus.SelectedValue.AsIntegerOrNull(); if (dpRequestDate.SelectedDate.HasValue) { benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value; } benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number; benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number; benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number; List <BenevolenceResultInfo> resultListUI = BenevolenceResultsState; var resultListDB = benevolenceRequest.BenevolenceResults.ToList(); // remove any Benevolence Results that were removed in the UI foreach (BenevolenceResult resultDB in resultListDB) { if (!resultListUI.Any(r => r.ResultId == resultDB.Id)) { benevolenceRequest.BenevolenceResults.Remove(resultDB); benevolenceResultService.Delete(resultDB); } } // add any Benevolence Results that were added in the UI foreach (BenevolenceResultInfo resultUI in resultListUI) { var resultDB = resultListDB.FirstOrDefault(r => r.Guid == resultUI.TempGuid); if (resultDB == null) { resultDB = new BenevolenceResult(); resultDB.BenevolenceRequestId = benevolenceRequest.Id; resultDB.Guid = resultUI.TempGuid; benevolenceRequest.BenevolenceResults.Add(resultDB); } resultDB.Amount = resultUI.Amount; resultDB.ResultSummary = resultUI.ResultSummary; resultDB.ResultTypeValueId = resultUI.ResultTypeValueId; } if (benevolenceRequest.IsValid) { if (benevolenceRequest.Id.Equals(0)) { benevolenceRequestService.Add(benevolenceRequest); } // get attributes benevolenceRequest.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phAttributes, benevolenceRequest); rockContext.WrapTransaction(() => { rockContext.SaveChanges(); benevolenceRequest.SaveAttributeValues(rockContext); }); // update related documents var documentsService = new BenevolenceRequestDocumentService(rockContext); // delete any images that were removed var orphanedBinaryFileIds = new List <int>(); var documentsInDb = documentsService.Queryable().Where(b => b.BenevolenceRequestId == benevolenceRequest.Id).ToList(); foreach (var document in documentsInDb.Where(i => !DocumentsState.Contains(i.BinaryFileId))) { orphanedBinaryFileIds.Add(document.BinaryFileId); documentsService.Delete(document); } // save documents int documentOrder = 0; foreach (var binaryFileId in DocumentsState) { // Add or Update the activity type var document = documentsInDb.FirstOrDefault(i => i.BinaryFileId == binaryFileId); if (document == null) { document = new BenevolenceRequestDocument(); document.BenevolenceRequestId = benevolenceRequest.Id; benevolenceRequest.Documents.Add(document); } document.BinaryFileId = binaryFileId; document.Order = documentOrder; documentOrder++; } rockContext.SaveChanges(); // redirect back to parent var personId = this.PageParameter("PersonId").AsIntegerOrNull(); var qryParams = new Dictionary <string, string>(); if (personId.HasValue) { qryParams.Add("PersonId", personId.ToString()); } NavigateToParentPage(qryParams); } } }