Пример #1
0
        public override bool Handle(ChangeRequestApprovedEvent changeRequestApprovedEvent)
        {
            if (_repositoryService != null && changeRequestApprovedEvent != null)
            {
                T deserializedEntity = Serializer.Deserialize <T>(changeRequestApprovedEvent.Payload);

                switch (changeRequestApprovedEvent.ChangeRequestStatus)
                {
                case ChangeRequestStatus.Submitted:           // note: this is never executed.
                case ChangeRequestStatus.PreliminaryApproved: // note: this is never executed.
                    break;

                case ChangeRequestStatus.Deleted:
                case ChangeRequestStatus.Rejected:
                    switch (changeRequestApprovedEvent.ChangeType)
                    {
                    case ChangeType.Delete:
                    case ChangeType.Modify:
                    case ChangeType.Replace:
                        T existingEntity = _repositoryService.FindAsync(Convert.ToInt32(changeRequestApprovedEvent.EntityId)).Result;
                        typeof(T).GetProperties()
                        .FirstOrDefault(p => p.GetCustomAttributes(typeof(ChangeRequestProperty), true).Any())?
                        .SetValue(existingEntity, null);
                        _repositoryService.Update(existingEntity);
                        break;
                    }
                    break;

                case ChangeRequestStatus.Approved:
                    switch (changeRequestApprovedEvent.ChangeType)
                    {
                    case ChangeType.None:         // note: this is never executed.
                        break;

                    case ChangeType.Delete:
                        // note: soft delete only
                        T existingEntity = _repositoryService.FindAsync(Convert.ToInt32(changeRequestApprovedEvent.EntityId)).Result;
                        this.UpdateEntity(ref existingEntity, ChangeType.Delete, changeRequestApprovedEvent.ChangeRequestId);
                        _repositoryService.Update(existingEntity);

                        break;

                    case ChangeType.Add:
                        this.UpdateEntity(ref deserializedEntity, ChangeType.Add, changeRequestApprovedEvent.ChangeRequestId);
                        _repositoryService.Add(deserializedEntity);
                        break;

                    case ChangeType.Modify:
                        this.UpdateEntity(ref deserializedEntity, ChangeType.Modify, changeRequestApprovedEvent.ChangeRequestId);
                        _repositoryService.Update(deserializedEntity);
                        break;

                    case ChangeType.Replace:
                        this.UpdateEntity(ref deserializedEntity, ChangeType.Replace, changeRequestApprovedEvent.ChangeRequestId);
                        _repositoryService.Update(deserializedEntity);
                        break;
                    }

                    break;

                default:
                    throw new Exception("Status type not found.");
                }
                // note: savechanges is performed at change request business service
            }

            return(true);
        }
Пример #2
0
 public abstract bool Handle(ChangeRequestApprovedEvent changeRequestApprovedEvent);