Example #1
0
        protected virtual IMovementConfirmationStateCreated Map(ICreateMovementConfirmation c)
        {
            var stateEventId = new MovementConfirmationEventId(c.DocumentNumber, c.Version);
            IMovementConfirmationStateCreated e = NewMovementConfirmationStateCreated(stateEventId);

            NewMovementConfirmationDocumentActionCommandAndExecute(c, _state, e);
            e.MovementDocumentNumber = c.MovementDocumentNumber;
            e.IsApproved             = c.IsApproved;
            e.ApprovalAmount         = c.ApprovalAmount;
            e.Processed      = c.Processed;
            e.Processing     = c.Processing;
            e.DocumentTypeId = c.DocumentTypeId;
            e.Description    = c.Description;
            e.Active         = c.Active;
            e.CommandId      = c.CommandId;


            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();
            var version = c.Version;

            foreach (ICreateMovementConfirmationLine innerCommand in c.MovementConfirmationLines)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IMovementConfirmationLineStateCreated innerEvent = MapCreate(innerCommand, c, version, _state);
                e.AddMovementConfirmationLineEvent(innerEvent);
            }


            return(e);
        }
        public virtual void When(IMovementConfirmationStateCreated e)
        {
            ThrowOnWrongEvent(e);
            this.DocumentStatusId = e.DocumentStatusId;

            this.MovementDocumentNumber = e.MovementDocumentNumber;

            this.IsApproved = (e.IsApproved != null && e.IsApproved.HasValue) ? e.IsApproved.Value : default(bool);

            this.ApprovalAmount = (e.ApprovalAmount != null && e.ApprovalAmount.HasValue) ? e.ApprovalAmount.Value : default(decimal);

            this.Processed = (e.Processed != null && e.Processed.HasValue) ? e.Processed.Value : default(bool);

            this.Processing = e.Processing;

            this.DocumentTypeId = e.DocumentTypeId;

            this.Description = e.Description;

            this.Active = (e.Active != null && e.Active.HasValue) ? e.Active.Value : default(bool);

            this.Deleted = false;

            this.CreatedBy = e.CreatedBy;
            this.CreatedAt = e.CreatedAt;

            foreach (IMovementConfirmationLineStateCreated innerEvent in e.MovementConfirmationLineEvents)
            {
                IMovementConfirmationLineState innerState = this.MovementConfirmationLines.Get(innerEvent.GlobalId.LineNumber, true);
                innerState.Mutate(innerEvent);
            }
        }
Example #3
0
        public virtual void Initialize(IMovementConfirmationStateCreated stateCreated)
        {
            var aggregateId = stateCreated.MovementConfirmationEventId.DocumentNumber;
            var state       = new MovementConfirmationState();

            state.DocumentNumber = aggregateId;
            var aggregate = (MovementConfirmationAggregate)GetMovementConfirmationAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            aggregate.Apply(stateCreated);
            Persist(eventStoreAggregateId, aggregate, state);
        }
        public virtual MovementConfirmationStateCreatedDto ToMovementConfirmationStateCreatedDto(IMovementConfirmationStateCreated e)
        {
            var dto = new MovementConfirmationStateCreatedDto();

            dto.MovementConfirmationEventId = e.MovementConfirmationEventId;
            dto.CreatedAt              = e.CreatedAt;
            dto.CreatedBy              = e.CreatedBy;
            dto.CommandId              = e.CommandId;
            dto.DocumentStatusId       = e.DocumentStatusId;
            dto.MovementDocumentNumber = e.MovementDocumentNumber;
            dto.IsApproved             = e.IsApproved;
            dto.ApprovalAmount         = e.ApprovalAmount;
            dto.Processed              = e.Processed;
            dto.Processing             = e.Processing;
            dto.DocumentTypeId         = e.DocumentTypeId;
            dto.Description            = e.Description;
            dto.Active = e.Active;
            var movementConfirmationLineEvents = new List <MovementConfirmationLineStateCreatedDto>();

            foreach (var ee in e.MovementConfirmationLineEvents)
            {
                MovementConfirmationLineStateCreatedDto eeDto = MovementConfirmationLineStateEventDtoConverter.ToMovementConfirmationLineStateCreatedDto(ee);
                movementConfirmationLineEvents.Add(eeDto);
            }
            dto.MovementConfirmationLineEvents = movementConfirmationLineEvents.ToArray();

            return(dto);
        }
 void IMovementConfirmationState.When(IMovementConfirmationStateCreated e)
 {
     throw new NotSupportedException();
 }
Example #6
0
        public virtual void Create(ICreateMovementConfirmation c)
        {
            IMovementConfirmationStateCreated e = Map(c);

            Apply(e);
        }
Example #7
0
        protected void NewMovementConfirmationDocumentActionCommandAndExecute(ICreateMovementConfirmation c, IMovementConfirmationState s, IMovementConfirmationStateCreated e)
        {
            var pCommandHandler = this.MovementConfirmationDocumentActionCommandHandler;
            var pCmdContent     = default(string);
            var pCmd            = new PropertyCommand <string, string> {
                Content = pCmdContent, GetState = () => s.DocumentStatusId, SetState = p => e.DocumentStatusId = p, OuterCommandType = CommandType.Create
            };

            pCmd.Context = this.State;
            pCommandHandler.Execute(pCmd);
        }