Example #1
0
        protected virtual void UpdateFacilityRegulatorSubmittalElement(Facility facility, FacilitySubmittalElementPacket <RegulatorFacilitySubmittalElementHeaderXmlObject> fsePacket)
        {
            FacilityRegulatorSubmittalElement frse = Repository.FacilityRegulatorSubmittalElements.GetForFacility(facility.CERSID, fsePacket.FacilitySubmittalElement.SubmittalElementID);

            var status      = (SubmittalElementStatus)fsePacket.FacilitySubmittalElement.StatusID;
            var type        = (SubmittalElementType)fsePacket.FacilitySubmittalElement.SubmittalElementID;
            var submittedOn = fsePacket.FacilitySubmittalElement.SubmittedDateTime.Value;

            bool frseUpdated = false;

            //if this submittal is accepted, then lets see if this is the most recent accepted.
            //if so, then update the FRSE with the LastAccepted PK and date/time.
            if (status == SubmittalElementStatus.Accepted)
            {
                var lastAccepted = GetMostRecentFSE(fsePacket);
                if ((lastAccepted != null && submittedOn > lastAccepted.SubmittedDateTime.Value) ||
                    (frse.LastAcceptedFacilitySubmittalElementOn == null || (frse.LastAcceptedFacilitySubmittalElementOn != null && frse.LastAcceptedFacilitySubmittalElementOn.Value < fsePacket.FacilitySubmittalElement.SubmittalActionDateTime)))
                {
                    frse.LastAcceptedFacilitySubmittalElementID = fsePacket.FacilitySubmittalElement.ID;
                    frse.LastAcceptedFacilitySubmittalElementOn = fsePacket.FacilitySubmittalElement.SubmittalActionDateTime;
                    frseUpdated = true;
                }
            }

            //now see if this is the most recent facility submittal element received for this submittal element.
            //if so, then lets update the LastSubmitted fields.
            var results = Repository.FacilitySubmittalElements.Search(CERSID: facility.CERSID, type: type);

            results = from r in results where r.StatusID != (int)SubmittalElementStatus.Draft && r.ID != fsePacket.FacilitySubmittalElement.ID select r;
            var lastFSE = results.OrderByDescending(p => p.SubmittedDateTime).FirstOrDefault();

            if ((lastFSE != null && submittedOn > lastFSE.SubmittedDateTime.Value) ||
                (frse.LastSubmittedFacilitySubmittalElementOn == null || (frse.LastSubmittedFacilitySubmittalElementOn != null && frse.LastSubmittedFacilitySubmittalElementOn.Value < fsePacket.FacilitySubmittalElement.SubmittedDateTime)))
            {
                frse.LastSubmittedFacilitySubmittalElementID = fsePacket.FacilitySubmittalElement.ID;
                frse.LastSubmittedFacilitySubmittalElementOn = fsePacket.FacilitySubmittalElement.SubmittedDateTime;
                frseUpdated = true;
            }

            Repository.FacilityRegulatorSubmittalElements.Save(frse);

            //update the last Fac Info
            if (fsePacket.FacilitySubmittalElement.SubmittalElementID == (int)SubmittalElementType.FacilityInformation)
            {
                if (ServiceManager.BusinessLogic.SubmittalElements.SetLastFacilityInfoSubmittal(fsePacket.FacilitySubmittalElement))
                {
                    TransactionScope.Connect(fsePacket.FacilitySubmittalElement.Facility);
                }

                frseUpdated = true;
            }

            if (frseUpdated)
            {
                TransactionScope.Connect(frse);
            }
        }
Example #2
0
 public void Connect(FacilityRegulatorSubmittalElement frse)
 {
     if (Transaction == null)
     {
         throw new InvalidOperationException("Transaction is required.");
     }
     frse.CheckNull("frse");
     Repository.FacilityRegulatorSubmittalElementEDTTransactions.EnsureExists(frse, Transaction);
 }