Exemple #1
0
 public void Connect(FacilitySubmittalElement fse)
 {
     if (Transaction == null)
     {
         throw new InvalidOperationException("Transaction is required.");
     }
     fse.CheckNull("fse");
     Repository.FacilitySubmittalElementEDTTransactions.EnsureExists(fse, Transaction);
 }
Exemple #2
0
        public ActionResult SubmittalStart(int organizationId, int CERSID, FormCollection form)
        {
            var      viewModel             = SystemViewModelData.BuildUpSubmittalStartViewModel(CERSID);
            var      isFacilityInfoChecked = false;
            var      fseIDs        = string.Empty;
            DateTime submittedDate = DateTime.Now;

            //Create FacilitySubmittalRecord
            FacilitySubmittal facilitySubmittal = new FacilitySubmittal();

            facilitySubmittal.ReceivedOn  = DateTime.Now;
            facilitySubmittal.SubmittedOn = submittedDate;
            Repository.FacilitySubmittals.Create(facilitySubmittal);

            foreach (var submittal in viewModel.ReadyToSubmitCollection)
            {
                var FSEIDValue = form[string.Format("submittCheckBox_{0}", submittal.CurrentSubmittalElement.SubmittalElementID)];
                var comments   = form[string.Format("regulatorText_{0}", submittal.CurrentSubmittalElement.SubmittalElementID)];

                if (!string.IsNullOrWhiteSpace(FSEIDValue))
                {
                    FacilitySubmittalElement submittalElement = Repository.FacilitySubmittalElements.GetByID(submittal.CurrentSubmittalElement.FSEID.Value);

                    //We do not want to submit unless the Faciilty Info Submittal Element has been chekced.
                    if (isFacilityInfoChecked || submittalElement.SubmittalElementID == (int)CERS.SubmittalElementType.FacilityInformation)
                    {
                        submittalElement.SubmittedByComments = comments;
                        Repository.FacilitySubmittalElements.Submit(submittalElement, facilitySubmittal);
                        isFacilityInfoChecked = true;

                        fseIDs += "," + submittalElement.ID.ToString();
                        Services.BusinessLogic.SubmittalElements.SetLastFacilityInfoSubmittal(submittalElement);
                    }
                }
            }

            Facility facility = Repository.Facilities.GetByID(CERSID);

            Repository.Organizations.Save(facility.Organization);
            Services.Events.CreateFacilitySubmittalNotification(facility, facilitySubmittal);
            if (fseIDs.Length > 1)
            {
                fseIDs = fseIDs.Remove(0, 1);
            }

            return(RedirectToRoute(GetRouteName(Part.Submittal, Part.Finish), new { organizationID = organizationId, CERSID = CERSID, FSID = facilitySubmittal.ID }));
        }
Exemple #3
0
        private void InventorySummaryButton_Click(object sender, RoutedEventArgs e)
        {
            ICERSSystemServiceManager services = ServiceLocator.GetSystemServiceManager(DataRepository);

            try
            {
                int fsid = 0;
                fsid = Convert.ToInt32(ISFsidTB.Text);

                services.BusinessLogic.SubmittalElements.HazardousMaterialsInventory.InventorySummary.Summary(Convert.ToInt32(fsid));

                // all this was done in Summary but we need the information to get the output
                FacilitySubmittal        fs  = (from fsRec in DataRepository.DataModel.FacilitySubmittals where fsRec.ID == fsid select fsRec).FirstOrDefault();
                FacilitySubmittalElement fse =
                    (from fseRec in DataRepository.DataModel.FacilitySubmittalElements
                     where fseRec.FacilitySubmittal.ID == fs.ID && fseRec.Voided == false &&
                     fseRec.SubmittalElementID == (int)SubmittalElementType.HazardousMaterialsInventory
                     select fseRec).FirstOrDefault();
                FacilitySubmittalElementResource fser =
                    (from fserRec in DataRepository.DataModel.FacilitySubmittalElementResources
                     where fserRec.FacilitySubmittalElementID == fse.ID &&
                     fserRec.Voided == false && fserRec.ResourceTypeID == (int)ResourceType.HazardousMaterialInventory
                     select fserRec).FirstOrDefault();

                InventorySummary inventory = DataRepository.InventorySummaries.GetByFSERID(fser.ID);
                StringBuilder    results   = new StringBuilder();
                results.Append("Inventory Summary  FSE: " + fse.ID + " CERSID: " + fse.CERSID + "\n");

                results.Append("   Solid Material Count: " + inventory.SolidMaterialCount + " EHS Count: " +
                               inventory.SolidEHSCount + " Maximum Daily Value: " + inventory.SolidMaximumDailyValue + " pounds\n");
                results.Append("   Liquid Material Count: " + inventory.LiquidMaterialCount + " EHS Count: " +
                               inventory.LiquidEHSCount + " Maximum Daily Value: " + inventory.LiquidMaximumDailyValue + " gallons\n");
                results.Append("   Gas Material Count: " + inventory.GasMaterialCount + " EHS Count: " +
                               inventory.GasEHSCount + " Maximum Daily Value: " + inventory.GasMaximumDailyValue + " cubic feet\n");
                results.Append("   Unique Location Count: " + inventory.UniqueLocationCount + "\n");

                this.OutputTB.Text = results.ToString();
            }
            catch (Exception ex)
            {
                this.OutputTB.Text = "Error: " + ex.Message;
            }
        }
Exemple #4
0
        public ActionResult OrganizationFacilitySubmittalEvent(int organizationID, int FSID)
        {
            FacilitySubmittalViewModel viewModel = SystemViewModelData.BuildUpFacilitySubmittalViewModel(FSID, organizationID);

            viewModel.FacilitySubmittalElements = viewModel.FacilitySubmittalElements.OrderBy(f => f.SubmittalElementID);

            //plug in HMI report
            FacilitySubmittalElement HMIFse = viewModel.FacilitySubmittalElements.Where(p => p.SubmittalElementID == (int)(SubmittalElementType.HazardousMaterialsInventory)).FirstOrDefault();

            if (HMIFse != null)
            {
                FacilitySubmittalElementResource HMIFser = HMIFse.Resources.Where(r => r.ResourceTypeID == (int)ResourceType.HazardousMaterialInventory && !r.Voided).FirstOrDefault();
                if (HMIFser != null)
                {
                    HazardousMaterialsInventoryController hmiController = new HazardousMaterialsInventoryController();
                    viewModel.HMISReport = hmiController.PopulateHMIMatrixViewModel(organizationID, HMIFse.CERSID, HMIFse.ID, HMIFser.ID);
                }
            }

            return(View(viewModel));
        }
        public XElement Process(Stream stream, int regulatorCode)
        {
            //make serializers needed
            RegulatorFacilitySubmittalResponseXmlSerializer           responseSerializer = new RegulatorFacilitySubmittalResponseXmlSerializer(Repository);
            RegulatorFacilitySubmittalActionNotificationXmlSerializer serializer         = new RegulatorFacilitySubmittalActionNotificationXmlSerializer(Repository);

            //contextRegulator is always the regulator this Processor is working under the context of. In this case, the assumption is, this Regulator is
            //ALWAYS a CUPA.
            Regulator contextRegulator = Repository.Regulators.GetByEDTIdentityKey(regulatorCode);

            if (contextRegulator == null)
            {
                throw new ArgumentException("RegulatorCode does not contain a valid number.", "regulatorCode");
            }

            TransactionScope.Connect(contextRegulator);

            XmlSchemaValidationResult schemaValidationResult = null;

            var rfsanXml = ConvertStreamToXDocument(stream);

            if (rfsanXml != null)
            {
                string xml = rfsanXml.ToString();
                TransactionScope.SaveXml(xml, EDTTransactionXmlDirection.Inbound);
                TransactionScope.WriteActivity("XML Document is validating...");

                schemaValidationResult = xml.IsValidAgainstSchema(XmlSchema.RegulatorFacilitySubmittalActionNotification);
                if (!schemaValidationResult.IsValid)
                {
                    //package is invalid due to schema validation errors, update the transaction status write some info.
                    //Merge in the schema validation error messages and associate them with the transaction.
                    TransactionScope.WriteActivity("XML Document is not valid against the schema.");
                    foreach (var error in schemaValidationResult.Errors)
                    {
                        TransactionScope.WriteMessage("Schema Validation Error: " + error, EDTTransactionMessageType.Error);
                    }
                    TransactionScope.WriteMessage("XML document does not validate against the schema.", EDTTransactionMessageType.Error);
                    TransactionScope.Complete(EDTTransactionStatus.Rejected);
                }
                else
                {
                    TransactionScope.WriteActivity("XML Document is valid against the schema.");

                    //deserialize the XML into an object graph package.
                    var package = serializer.Deserialize(rfsanXml);
                    TransactionScope.SetEDTClientKey(package.RegulatorTransactionKey);
                    int totalErrorCount = 0;
                    int errorCount      = 0;

                    //lets analyze and process each one.
                    foreach (var se in package.Packets)
                    {
                        errorCount = 0;
                        var targetSE = Repository.FacilitySubmittalElements.FindByKey(se.CERSUniqueKey.Value);
                        if (targetSE != null)
                        {
                            //verify the CERSID from the XML matches the FSE
                            if (targetSE.CERSID != se.CERSID.Value)
                            {
                                errorCount++;
                                TransactionScope.WriteMessage("Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' does not belong to CERSID '" + se.CERSID.Value + "'.", EDTTransactionMessageType.Error);
                            }

                            //Verify the SubmittalElementID from the XML matches the FSE
                            if (targetSE.SubmittalElementID != (int)se.SubmittalElement.Value)
                            {
                                errorCount++;
                                TransactionScope.WriteMessage("Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' is not a Submittal Element of type '" + (int)se.SubmittalElement.Value + "'.", EDTTransactionMessageType.Error);
                            }

                            if (targetSE.SubmittalActionDateTime.HasValue)
                            {
                                //verify the SubmittalActionDateTime on the existing FSE is prior to the SubmittalActionDateTime on the targetFSE (from XML)
                                if (se.ActionOn.Value < targetSE.SubmittalActionDateTime.Value)
                                {
                                    TransactionScope.WriteMessage("The SubmittalActionOn value must be greater than the existing SubmittalActionOn value (" + targetSE.SubmittalActionDateTime.Value.ToString() + ") for Submittal Element with CERSUniqueKey " + se.CERSUniqueKey.Value.ToString() + ".", EDTTransactionMessageType.Error);
                                }
                            }

                            //Get the Facility, and make sure it exists first.
                            Facility facility = Repository.Facilities.GetByID(targetSE.CERSID);
                            if (facility != null)
                            {
                                //figure out the CUPA.
                                var CUPARegulator = Repository.Facilities.GetCUPA(facility);
                                if (CUPARegulator != null)
                                {
                                    //Ensure that the Facilities CUPA is associated with the CUPA calling this processor.
                                    if (contextRegulator.ID != CUPARegulator.ID)
                                    {
                                        errorCount++;
                                        TransactionScope.WriteMessage("Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' is assigned to a CUPA the current account is not authorized to submit for.", EDTTransactionMessageType.Error);
                                    }
                                }
                                else
                                {
                                    errorCount++;
                                    TransactionScope.WriteMessage("Cannot identify the CUPA for the Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "'.", EDTTransactionMessageType.Error);
                                }
                            }
                            else
                            {
                                errorCount++;
                                TransactionScope.WriteMessage("A facility with CERSID '" + targetSE.CERSID + "' cannot be found and therefore Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' cannot be updated/found.", EDTTransactionMessageType.Error);
                            }

                            //Get the regulator that is described in the XML as the Regulating body that is changing the submittal action information.
                            var regulator = Repository.Regulators.GetByEDTIdentityKey(se.RegulatorCode.Value);
                            if (regulator != null)
                            {
                                se.TargetRegulator = regulator;
                            }
                            else
                            {
                                errorCount++;
                                TransactionScope.WriteMessage("Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' specifies '" + se.RegulatorCode.Value + "' for the RegulatorCode element which is not valid.", EDTTransactionMessageType.Error);
                            }

                            //make sure that NextDueDate is in the future.
                            if (se.NextDueDate != null)
                            {
                                if (se.NextDueDate.Value < DateTime.Now)
                                {
                                    errorCount++;
                                    TransactionScope.WriteMessage("Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' has a NextDueDate of '" + se.NextDueDate.Value + "' which occurs in the past and is not allowed.", EDTTransactionMessageType.Error);
                                }
                            }
                        }
                        else
                        {
                            errorCount++;
                            TransactionScope.WriteMessage("Facility Submittal Element with CERSUniqueKey '" + se.CERSUniqueKey.Value.ToString() + "' was not found.", EDTTransactionMessageType.Error);
                        }

                        if (errorCount == 0)
                        {
                            se.FacilitySubmittalElement = targetSE;
                        }

                        totalErrorCount += errorCount;
                    }

                    if (totalErrorCount > 0)
                    {
                        TransactionScope.WriteActivity("Found " + totalErrorCount + " total error(s) with package. Setting to Rejected.");
                        TransactionScope.Complete(EDTTransactionStatus.Rejected);
                    }
                    else
                    {
                        try
                        {
                            FacilitySubmittalElement fse = null;

                            //all is good, so lets update them all and process it.
                            foreach (var se in package.Packets)
                            {
                                fse = se.FacilitySubmittalElement;
                                if (fse != null)
                                {
                                    ServiceManager.BusinessLogic.SubmittalElements.UpdateFacilitySubmittalElementStatus
                                    (
                                        fse,
                                        se.Status.Value,
                                        se.ActionOn,
                                        se.Comments,
                                        se.NextDueDate,
                                        Repository.ContextAccount,
                                        se.TargetRegulator.ID,
                                        se.AgentName,
                                        se.AgentEmail,
                                        submittalActionEDTTransaction: TransactionScope.Transaction
                                    );

                                    TransactionScope.Connect(fse);
                                }
                            }
                            TransactionScope.WriteActivity("All Facility Submittal Elements (" + package.Packets + ") updated successfully.");
                            TransactionScope.SetStatus(EDTTransactionStatus.Accepted);
                            TransactionScope.SetProcessedOn();
                        }
                        catch (Exception ex)
                        {
                            TransactionScope.WriteActivity("Errors occurred persisting updates to database.", ex);
                            TransactionScope.Complete(EDTTransactionStatus.ErrorProcessing);
                        }
                    }
                }
            }
            else
            {
                TransactionScope.WriteMessage("No package received.", EDTTransactionMessageType.Error);
                TransactionScope.Complete(EDTTransactionStatus.ErrorProcessing);
            }

            XElement responseXml = responseSerializer.PreparePackage(TransactionScope.Transaction);

            responseSerializer.AddTransaction(responseXml, TransactionScope.Transaction);
            responseSerializer.AddSummary(responseXml, TransactionScope.Transaction);
            TransactionScope.SaveXml(responseXml, EDTTransactionXmlDirection.Outbound);
            return(responseXml);
        }
Exemple #6
0
        protected virtual void PostProcessFacilityInformationSubmittalElementBusinessLogic(FacilitySubmittalElement fse)
        {
            if (fse == null)
            {
                throw new ArgumentNullException("fse");
            }

            if (fse.SubmittalElementID != (int)SubmittalElementType.FacilityInformation)
            {
                throw new ArgumentException("The FacilitySubmittalElement is not a Facility Information submittal element.", "fse");
            }

            //get each form again.
            var bpActivity = ServiceManager.FacilitySubmittalModelEntities.GetSingleEntity <BPActivity>(fse, ResourceType.BusinessActivities);

            if (bpActivity != null)
            {
                ServiceManager.BusinessLogic.SubmittalElements.FacilityInformation.PostSaveActivitiesForm(fse, bpActivity, CallerContext.EDT);
            }

            var bpOwnerOperator = ServiceManager.FacilitySubmittalModelEntities.GetSingleEntity <BPOwnerOperator>(fse, ResourceType.BusinessOwnerOperatorIdentification);

            if (bpOwnerOperator != null)
            {
                ServiceManager.BusinessLogic.SubmittalElements.FacilityInformation.PostSaveOwnerOperatorForm(fse, bpOwnerOperator, CallerContext.EDT);
            }
        }
Exemple #7
0
 /// <summary>
 /// Returns a specific Entity for specified <see cref="FacilitySubmittalElement"/>, <see cref="ResourceType"/>, and
 /// fserID (FacilitySubmittalElementResourceID).  For use with ONE-to-MANY FSE-to-FSER relationships only, such as
 /// USTTankInfo, USTMonitoringPlan, USTInstallModCert, etc.
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <param name="fse"></param>
 /// <param name="resourceType"></param>
 /// <param name="fserID">Providing a value of zero will generate an pre-configured model of the appropriate Resource
 /// Type for the specified FSE and ResourceType, to assist with the Create views. A non-zero value will retrieve the
 /// existing Resource for the FSE and FSERID.</param>
 /// <returns></returns>
 protected virtual TModel GetSpecificEntity <TModel>(FacilitySubmittalElement fse, ResourceType resourceType, int fserID) where TModel : class, IFacilitySubmittalModelEntity, new()
 {
     return(Services.FacilitySubmittalModelEntities.GetSpecificEntity <TModel>(fse, resourceType, fserID));
 }
Exemple #8
0
        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));
        }
Exemple #9
0
 /// <summary>
 /// Deletes the Entity linked to the <see cref="FacilitySubmittalElement"/> of the specified Resource Type.
 /// and FSER (Resource) ID.  This should only be used for one-to-many relationships, such as USTTankInfo,
 /// USTMonitoringPlan, USTInstallModCert, etc.
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <param name="fse"></param>
 /// <param name="resourceType"></param>
 /// <param name="fserID"></param>
 protected virtual void DeleteSpecificEntity(FacilitySubmittalElement fse, ResourceType resourceType, int fserID)
 {
     Services.FacilitySubmittalModelEntities.DeleteSpecificEntity(fse, resourceType, fserID);
 }
Exemple #10
0
        /// <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);
        }
Exemple #11
0
 /// <summary>
 /// Deletes the Entity linked to the <see cref="FacilitySubmittalElement"/> of the specified Resource Type.
 /// This should only be used for one-to-one relationships, such as BPActivities, BPOwnerOperator,
 /// USTFacilityInfo, etc.
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <param name="fse"></param>
 /// <param name="resourceType"></param>
 protected virtual void DeleteSingleEntity(FacilitySubmittalElement fse, ResourceType resourceType)
 {
     Services.FacilitySubmittalModelEntities.DeleteSingleEntity(fse, resourceType);
 }