public DtoDatabaseOperationOutcome()
 {
     this.ReturnedResourceList  = new List <DtoResource>();
     this.RecourceIsDeleted     = false;
     this.ResourceVersionNumber = 0;
     SingleResourceRead         = false;
     TriggerOutCome             = null;
 }
Ejemplo n.º 2
0
 private ITriggerOutcome CollateOutcomes(ITriggerOutcome TriggerOutcomeMain, ITriggerOutcome TriggerOutcomeNew)
 {
     if (TriggerOutcomeMain == null)
     {
         return(TriggerOutcomeNew);
     }
     else
     {
         if (!TriggerOutcomeMain.Report && TriggerOutcomeNew.Report)
         {
             //The main does not need to report but the new one does so just return the new one
             return(TriggerOutcomeNew);
         }
         else if (TriggerOutcomeMain.Report && TriggerOutcomeNew.Report)
         {
             //Both Main and New need to report so collate the OperationOutcome Issue lists into a single OperationOutcome.
             if (TriggerOutcomeMain.Resource != null && TriggerOutcomeMain.Resource is OperationOutcome OptOutMain)
             {
                 if (TriggerOutcomeNew.Resource != null && TriggerOutcomeNew.Resource is OperationOutcome OptOut)
                 {
                     OptOutMain.Issue.AddRange(OptOut.Issue);
                     return(TriggerOutcomeMain);
                 }
             }
             throw new System.InvalidCastException("Internal Server Error: ITriggerOutcome Resource is not an OperationOutcome");
         }
         else if (TriggerOutcomeMain.Report && !TriggerOutcomeNew.Report)
         {
             //The new does not need to report but the Main does so return only the Main
             return(TriggerOutcomeMain);
         }
         else
         {
             //Both do not need to report so just return the New as it will not be null;
             return(TriggerOutcomeNew);
         }
     }
 }
Ejemplo n.º 3
0
        public ITriggerOutcome ProcessTrigger(ITriggerInput TriggerInput)
        {
            //If triggers are not active then just return Report as False
            if (!_TriggersActive)
            {
                return new TriggerOutcome()
                       {
                           Report = false
                       }
            }
            ;

            //Validate TriggerInput
            if (TriggerInput.CrudOperationType == RestEnum.CrudOperationType.None)
            {
                throw new System.NullReferenceException("TriggerInput.CrudOperationType cannot be None");
            }

            if (TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Create ||
                TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Update)
            {
                if (TriggerInput.InboundResource == null)
                {
                    throw new System.NullReferenceException("TriggerInput.InboundResource cannot be null");
                }
            }

            if (TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Create ||
                TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Update ||
                TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Delete)
            {
                if (string.IsNullOrWhiteSpace(TriggerInput.InboundResourceId))
                {
                    throw new System.NullReferenceException("TriggerInput.InboundResourceId cannot be null or empty");
                }
                if (TriggerInput.ResourceType == ResourceType.Resource)
                {
                    throw new System.NullReferenceException("TriggerInput.ResourceType cannot be equal to 'Resource'");
                }
            }

            if (TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Update ||
                TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Delete)
            {
                if (TriggerInput.DbTokenIndexList == null)
                {
                    throw new System.NullReferenceException("TriggerInput.DbTokenIndexList cannot be null for Update or Delete actions");
                }
            }

            ITriggerOutcome TriggerOutcomeMain = null;

            //Resource Specific
            var ResourceSpecificList = ITriggerServiceList.Where(x => x.ResourceTypeToTriggerFor == TriggerInput.ResourceType);

            foreach (var TriggerService in ResourceSpecificList)
            {
                TriggerOutcomeMain = CollateOutcomes(TriggerOutcomeMain, TriggerService.ProcessTrigger(TriggerInput));
            }

            //All Resource Types
            ResourceSpecificList = ITriggerServiceList.Where(x => x.ResourceTypeToTriggerFor == ResourceType.Resource);
            foreach (var TriggerService in ResourceSpecificList)
            {
                TriggerOutcomeMain = CollateOutcomes(TriggerOutcomeMain, TriggerService.ProcessTrigger(TriggerInput));
            }

            return(TriggerOutcomeMain);
        }