protected void ProcessSubmittalElements(SubmittalElementStatus status, SubmittalElementType type) { int fseIndex = 0; int fseCount = 0; XmlSerializationResult serializationResult = null; List <FacilitySubmittalElement> fses = null; bool unprocessedOnly = true; OnNotification("Fetching " + (unprocessedOnly ? " Unprocessed " : "") + " '" + status.ToString() + "' FSE Records for '" + type.ToString() + "'..."); fses = Repository.FacilitySubmittalElements.EDTBatchSearch(type, status, unprocessed: unprocessedOnly).ToList(); fseCount = fses.Count; fseIndex = 0; OnNotification("Fetched " + (unprocessedOnly ? " Unprocessed " : "") + " '" + status.ToString() + "' FSE Records for " + type.ToString() + ". Processing " + fseCount + " FSE's..."); foreach (var fse in fses) { try { serializationResult = Repository.FacilitySubmittalElements.UpdateXmlMetadata(fse, saveChanges: true, ignoreCommonFieldUpdate: true); serializationResult.Xml = null; serializationResult.Schema = null; serializationResult = null; OnNotification("Updated XML For '" + type + "' (" + status + ") FSEID: " + fse.ID + " (" + fseIndex + " of " + fseCount + ")"); } catch (Exception ex) { OnNotification("Problem updating " + fse.ID + ".", ex: ex); } fseIndex++; CalculateProgress(fseIndex, fseCount); GC.Collect(); } }
protected virtual FacilitySubmittalElement GetMostRecentFSE(FacilitySubmittalElementPacket <RegulatorFacilitySubmittalElementHeaderXmlObject> fsePacket) { SubmittalElementStatus status = (SubmittalElementStatus)fsePacket.FacilitySubmittalElement.StatusID; SubmittalElementType type = (SubmittalElementType)fsePacket.FacilitySubmittalElement.SubmittalElementID; return(GetMostRecentFSE(fsePacket.FacilitySubmittalElement.CERSID, type, status, fsePacket.FacilitySubmittalElement.ID)); }
protected virtual FacilitySubmittalElement GetMostRecentFSE(int CERSID, SubmittalElementType type, SubmittalElementStatus status, int thisFSEID) { var result = Repository.FacilitySubmittalElements .Search(CERSID: CERSID, type: type, status: status) .Where(p => p.ID != thisFSEID) .OrderByDescending(p => p.SubmittedDateTime) .FirstOrDefault(); return(result); }
protected string GetUrlForForm(int CERSID, SubmittalElementType submittalElement, ResourceType resource, RouteValueDictionary routeValues) { string result = null; string routeName = GetDraftFormRouteName(CERSID, submittalElement, resource); var routeVirtualPath = RouteTable.Routes.GetVirtualPath(null, routeName, routeValues); if (routeVirtualPath != null) { result = routeVirtualPath.VirtualPath; } return(result); }
/// <summary> /// Generically returns a <see cref="FacilitySubmittalElementResourceViewMode{TModel}"/> for one-to-one relationships /// (BPActivities, BPOwnerOperator, USTFacilityInfo, etc.). This method will retrieve the only resource available for /// the specified Resource Type for this <see cref="FacilitySubmittalElement"/>. If no <see cref="FacilitySubmittalElement"/> exists, the /// call to 'GetFacilitySubmittalElement' automatically generates the appropriate <see cref="FacilitySubmittalElementResource"/> records. /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="organziationID"></param> /// <param name="CERSID"></param> /// <param name="submittalElement"></param> /// <param name="resourceType"></param> /// <param name="fseId"></param> /// <param name="fserID"></param> /// <returns></returns> protected virtual FacilitySubmittalElementResourceViewModel <TModel> GetSingleEntityViewModel <TModel>(int organziationID, int CERSID, SubmittalElementType submittalElement, ResourceType resourceType, int?fseID = null) where TModel : class, IFacilitySubmittalModelEntity, new() { return(Services.ViewModels.GetSingleEntityViewModel <TModel>(organziationID, CERSID, submittalElement, resourceType, fseID)); }
public virtual ActionResult Handle_LandingPageGet(int organizationId, int CERSID, SubmittalElementType submittalElementType, ResourceType resourceType, string instructions, IEnumerable <WhatsNextItem> whatsNext, int?fseID = null, int?fserID = null) { LandingPageViewModel viewModel = new LandingPageViewModel(); FacilitySubmittalElement fse = null; if (fseID != null) { //since we have an fseID parameter this means we are pulling up an existing submittal //which could also mean, we also need to check the status of this FacilitySubmittalElement to see whether editing is allowed. // fse = Services.BusinessLogic.SubmittalElements.GetFacilitySubmittalElement(fseID.Value); if (fse.CERSID != CERSID) { throw new Exception("The CERSID and the FacilitySubmittalElementID do not belong to one another. This is probably an attempt to breach security."); } //When the submittal element is in draft, editing is allowed, but not in ANY other status. } else { //in this particlar case, we ALWAYS bring back a Draft submittal element. The method below locates an existing draft is there is one OR creates on, if there //is no active draft for the submittal element. fse = Services.BusinessLogic.SubmittalElements.GetFacilitySubmittalElement(CERSID, submittalElementType, SubmittalElementStatus.Draft, true); } //at this point, we should have a FacilitySubmittalElement to work against, if not (should not happen) lets blow up. if (fse == null) { throw new Exception("Unable to find a usable FacilitySubmittalElement."); } viewModel.FacilitySubmittalElement = fse; // Get Resource FacilitySubmittalElementResource resource = new FacilitySubmittalElementResource(); if (fserID == null) { // If fserID is not specified, retrieve the first resource for this FSE and ResourceType resource = fse.Resources.FirstOrDefault(p => p.ResourceTypeID == (int)resourceType && !p.Voided); } else { // If fserID *is* specified, resource ID must match the specified value // Use "SingleOrDefault" - specifying by fserID should never return more than one record resource = fse.Resources.SingleOrDefault(p => p.ResourceTypeID == (int)resourceType && p.ID == fserID && !p.Voided); } // Set ViewModel Resource viewModel.FacilitySubmittalElementResource = resource; //Get current submittal element view model var currentSubmittalElement = Repository.FacilityRegulatorSubmittalElements.GetCurrentFacilitySubmittalElements(CERSID, (int)submittalElementType).FirstOrDefault(); CurrentSubmittalElementViewModel viewModelcurrSub = new CurrentSubmittalElementViewModel() { CurrentSubmittalElement = currentSubmittalElement, OrganizationID = organizationId, isFirstElement = true }; //Set current submittal element view model viewModel.CurrentSEViewModel = viewModelcurrSub; //Get guidance. var guidance = Repository.GuidanceMessages.Search(facilitySubmittalElementResourceID: viewModel.FacilitySubmittalElementResource.ID).ToList(); if (guidance == null) { guidance = new List <GuidanceMessage>(); } //Set Guidance Messages viewModel.GuidanceMessages = guidance; //Set Instructions viewModel.Instructions = instructions; //Set WhatsNext viewModel.WhatsNext = whatsNext; return(View(viewModel)); }
/// <summary> /// Builds up the Supplemental Document pages view model. /// </summary> /// <param name="organizationId"></param> /// <param name="CERSID"></param> /// <param name="submittalElementType"></param> /// <param name="resourceType"></param> /// <param name="fseID"></param> /// <returns></returns> protected virtual DocumentUploadViewModel BuildUpDocumentUploadViewModel(int organizationId, int CERSID, SubmittalElementType submittalElementType, ResourceType resourceType, int?fseID = null, int?fserID = null) { //declare the viewModel DocumentUploadViewModel viewModel = new DocumentUploadViewModel(); viewModel.OrganizationID = organizationId; FacilitySubmittalElement fse = null; if (fseID != null) { //since we have an fseID parameter this means we are pulling up an existing submittal //which could also mean, we also need to check the status of this FacilitySubmittalElement to see whether editing is allowed. // fse = Services.BusinessLogic.SubmittalElements.GetFacilitySubmittalElement(fseID.Value); if (fse.CERSID != CERSID) { throw new Exception("The CERSID and the FacilitySubmittalElementID do not belong to one another. This is probably an attempt to breach security."); } //When the submittal element is in draft, editing is allowed, but not in ANY other status. viewModel.EditingAllowed = ((SubmittalElementStatus)fse.StatusID == SubmittalElementStatus.Draft); } else { //in this particlar case, we ALWAYS bring back a Draft submittal element. The method below locates an existing draft is there is one OR creates on, if there //is no active draft for the submittal element. fse = Services.BusinessLogic.SubmittalElements.GetFacilitySubmittalElement(CERSID, submittalElementType, SubmittalElementStatus.Draft, true); } //at this point, we should have a FacilitySubmittalElement to work against, if not (should not happen) lets blow up. if (fse == null) { throw new Exception("Unable to find a usable FacilitySubmittalElement."); } viewModel.FacilitySubmittalElement = fse; //Get resource. var resource = fse.Resources.FirstOrDefault(p => p.ResourceTypeID == (int)resourceType && !p.Voided); if (fserID != null) { resource = fse.Resources.SingleOrDefault(p => p.ResourceTypeID == (int)resourceType && !p.Voided && p.ID == fserID); } //Documents can be voided. In that case the resource will be null. So, spin up a new resource. if (resource == null) { //Make sure the resource type is Document. If not, then there are bigger problems. var isDocument = Repository.SystemLookupTables.ResourceTypes.Where(p => !p.Voided && p.DocumentTypeID != null && p.ID == (int)resourceType); if (isDocument != null) { SubmittalElementTemplateResource setr = Repository.SubmittalElementTemplateResources.Search(submittalElementID: fse.SubmittalElementID, templateID: fse.TemplateID, typeID: (int)resourceType).SingleOrDefault(); var parentResource = fse.Resources.Where(r => !r.Voided && r.ResourceTypeID == setr.ParentResourceID).FirstOrDefault(); resource = fse.AddResource(setr, parentResource, true); } } //Set viewModle resource viewModel.FacilitySubmittalElementResource = resource; //Get Entity viewModel.Entity = resource.FacilitySubmittalElementResourceDocuments.FirstOrDefault(p => !p.Voided); //Create viewModel.Document //If entity is null nothing was found above. Create new Entity object if (viewModel.Entity == null) { viewModel.Entity = new FacilitySubmittalElementResourceDocument(); viewModel.Entity.SetCommonFields(CurrentAccountID, true); } else { if (viewModel.Entity.SourceID == (int)DocumentSource.Exempt) { viewModel.ExemptComments = viewModel.Entity.Comments; } else if (viewModel.Entity.SourceID == (int)DocumentSource.ProvidedInOtherSubmittalElement) { viewModel.ProvidedInSubmittalElementComments = viewModel.Entity.Comments; } } //Get existing Documents. viewModel.Documents = viewModel.Entity.Documents.Where(p => !p.Voided); #region Load list values //Get DocumentSources for source radio button list. i.e. exempt, other Submittal Element, stored at Facility. viewModel.DocumentSources = new SelectList(Repository.SystemLookupTables.GetValues(SystemLookupTable.DocumentSource), "ID", "Name"); //Get otherSubmittalElements the documents could be included in. var otherSubmittalElements = Repository.FacilityRegulatorSubmittalElements.GetCurrentFacilitySubmittalElements(CERSID).Where(p => p.ReportingRequirementID != (int)ReportingRequirement.NotApplicable); viewModel.OtherSubmittalElements = (from se in otherSubmittalElements select new SelectListItem { Value = se.SubmittalElementID.ToString(), Text = se.Name }).ToList(); //Get other facilities documents could be stored at. viewModel.Facilities = (from f in Repository.Facilities.Search(organizationID: organizationId) select new SelectListItem { Value = f.CERSID.ToString(), Text = f.Name }).ToList(); #endregion Load list values //SET DEFAULT VALUES //Set entity.LinkUrl default value. if (string.IsNullOrEmpty(viewModel.Entity.LinkUrl)) { viewModel.Entity.LinkUrl = "http://"; } //Set default date in Date Authored field of "Document Upload" viewModel.DocumentDate = DateTime.Today; //default name for the document viewModel.Name = resource.Type.Name.ToLower().Trim().Contains("locally-required") || resource.Type.Name.ToLower().Trim().Contains("state-required") ? "" : resource.Type.Name; return(viewModel); }
public virtual ActionResult Handle_DocumentUploadPost(int organizationId, int CERSID, SubmittalElementType submittalElementType, ResourceType resourceType, DocumentUploadViewModel formValues, int?fseId = null, int?fserID = null) { Server.ScriptTimeout = 180; bool isValid = true; var viewModel = BuildUpDocumentUploadViewModel(organizationId, CERSID, submittalElementType, resourceType, fseId, fserID); var entity = viewModel.Entity; Document document = null; HttpPostedFileBase file = null; int? typeID; int? formatID; string errorHelper; if (TryUpdateModel(entity, "Entity")) { isValid = ValidateDocumentUploadViewModel(formValues, entity, ref file, (int)resourceType, out typeID, out formatID, out errorHelper); //must set all file values before validating model. if (ModelState.IsValid && isValid) { //See if this is a delete document action entity.Resource = viewModel.FacilitySubmittalElementResource; entity.Resource.IsDocument = true; entity.Resource.IsStarted = true; entity.Resource.DocumentSourceID = viewModel.Entity.SourceID; #region Save Everything if (formValues.ActionSourceID == (int)DocumentSource.UploadDocuments && formValues.ActionValue.Contains("Save")) { try { document = Repository.Documents.Save(file.InputStream, file.FileName, DocumentContext.Organization, organizationId); } catch (Exception ex) { ModelState.AddModelError("File", "Unable to save file. " + ex.Message); isValid = false; } if (document != null) { FacilitySubmittalElementDocument fseDocument = new FacilitySubmittalElementDocument(); fseDocument.DocumentID = document.ID; fseDocument.TypeID = typeID.Value; fseDocument.FormatID = formatID.Value; fseDocument.Name = formValues.Name; fseDocument.FileName = Path.GetFileName(file.FileName); fseDocument.FileSize = file.ContentLength; fseDocument.DocumentDate = formValues.DocumentDate.Value; fseDocument.Description = formValues.Description; fseDocument.Key = Guid.NewGuid(); // initialize EDTClientKey even if not EDT so that EDT RFSQ's have a DocumentRegulatorKey element under the Attachment element fseDocument.SetDDCommonFields(CurrentAccountID, true, edtClientKey: Guid.NewGuid().ToString()); entity.Documents.Add(fseDocument); Repository.DataModel.SaveChanges(); } } if (formValues.ActionSourceID.IfInRange(Repository.SystemLookupTables.DocumentSources.Select(p => p.ID).ToArray()) && formValues.ActionValue.Contains("Save")) { //Save FacilitySubmittalElementResourceDocuemnt entity.Resource.UpdateResourceEntityCount(); Repository.FacilitySubmittalElementResourceDocuments.Save(entity); //Validate this Submittal Element entity.Resource.FacilitySubmittalElement.ValidateAndCommitResults(Repository, CallerContext.UI); var fser = Repository.FacilitySubmittalElementResources.GetByID(entity.Resource.ID); //Set LastSubmittalDeltaId for FSE fser.SetLastSubmittalDelta(entity, CERSID, Repository); if (formValues.ActionValue.Contains("Continue") || formValues.ActionValue.Contains("Again")) { //redirect to Edit return(RedirectToAction("Edit_" + resourceType.ToString(), new { organizationId = organizationId, CERSID = CERSID, FSEID = fser.FacilitySubmittalElementID })); } else { //redirect to Org home page (aka crazy page) return(RedirectToRoute(OrganizationFacility.Home, new { organizationId = organizationId, CERSID = CERSID })); } } if (!string.IsNullOrWhiteSpace(formValues.ActionValue) && formValues.ActionValue.Contains("Delete Document")) { //get the id from the action name. string actionName = formValues.ActionValue; int underscoreIndex = (actionName.IndexOf("_")) + 1; int fseDocumentID; if (int.TryParse(actionName.Substring(underscoreIndex), out fseDocumentID)) { var documentToDelete = Repository.FacilitySubmittalElementDocuments.GetByID(fseDocumentID); try { //void the facilitySubmittalElementDoucment documentToDelete.SetCommonFields(CurrentAccountID, false, true); documentToDelete.FacilitySubmittalElementResourceDocument.Resource.UpdateResourceEntityCount(); documentToDelete.FacilitySubmittalElementResourceDocument.SetCommonFields(CurrentAccountID); Repository.FacilitySubmittalElementDocuments.Save(documentToDelete); //Set LastSubmittalDeltaId for FSER //Repository.FacilitySubmittalElementResourceDocuments.SetLastSubmittalDelta(entity, CERSID); //Set LastSubmittalDeltaId for FSE var fser = Repository.FacilitySubmittalElementResources.GetByID(entity.FacilitySubmittalElementResourceID); //fser.FacilitySubmittalElement.SetLastSubmittalDelta(Repository); fser.SetLastSubmittalDelta(entity, CERSID, Repository); //redirect to edit page. return(RedirectToAction("Edit_" + resourceType.ToString())); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } } #endregion Save Everything } } return(View(viewModel)); }
public virtual ActionResult Handle_DocumentUploadGet(int organizationId, int CERSID, SubmittalElementType submittalElementType, ResourceType resourceType, int?fseID = null, int?fserID = null) { var viewModel = BuildUpDocumentUploadViewModel(organizationId, CERSID, submittalElementType, resourceType, fseID, fserID); return(View(viewModel)); }
public virtual ActionResult Handle_Cloning(int organizationId, int CERSID, int FSEID, SubmittalElementType submittalElementType) { //This time persist the new fse var fseCurrentDraft = Services.BusinessLogic.SubmittalElements.GetFacilitySubmittalElement(CERSID, submittalElementType, SubmittalElementStatus.Draft, true); Repository.FacilitySubmittalElements.CloneWithEntities(CERSID, FSEID, fseCurrentDraft); //Sets the LastSubmittalDelta fseCurrentDraft.SetLastSubmittalDelta(Repository); fseCurrentDraft.ValidateAndCommitResults(Repository, CallerContext.UI); //If the SubmittalElementType is Facility Information, set the Reporting Requirements per the Biz Activities form if (fseCurrentDraft.SubmittalElementID == (int)SubmittalElementType.FacilityInformation) { Services.BusinessLogic.SubmittalElements.FacilityInformation.UpdateFRSEFromBizActivities(fseCurrentDraft); } return(RedirectToRoute("OrganizationFacilityHome", new { organizationID = organizationId, CERSID = CERSID })); }