Ejemplo n.º 1
0
        public virtual void When(IMovementStateCreated e)
        {
            ThrowOnWrongEvent(e);
            this.DocumentStatusId = e.DocumentStatusId;

            this.MovementDate = (e.MovementDate != null && e.MovementDate.HasValue) ? e.MovementDate.Value : default(DateTime);

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

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

            this.Processing = e.Processing;

            this.DateReceived = (e.DateReceived != null && e.DateReceived.HasValue) ? e.DateReceived.Value : default(DateTime);

            this.DocumentTypeId = e.DocumentTypeId;

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

            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.ShipperId = e.ShipperId;

            this.SalesRepresentativeId = e.SalesRepresentativeId;

            this.BusinessPartnerId = e.BusinessPartnerId;

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

            this.CreateFrom = e.CreateFrom;

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

            this.ReversalDocumentNumber = e.ReversalDocumentNumber;

            this.WarehouseIdFrom = e.WarehouseIdFrom;

            this.WarehouseIdTo = e.WarehouseIdTo;

            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 (IMovementLineStateCreated innerEvent in e.MovementLineEvents)
            {
                IMovementLineState innerState = this.MovementLines.Get(innerEvent.GlobalId.LineNumber, true);
                innerState.Mutate(innerEvent);
            }
        }
Ejemplo n.º 2
0
        public virtual void Initialize(IMovementStateCreated stateCreated)
        {
            var aggregateId = stateCreated.MovementEventId.DocumentNumber;
            var state       = new MovementState();

            state.DocumentNumber = aggregateId;
            var aggregate = (MovementAggregate)GetMovementAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            aggregate.Apply(stateCreated);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Ejemplo n.º 3
0
        protected virtual IMovementStateCreated Map(ICreateMovement c)
        {
            var stateEventId        = new MovementEventId(c.DocumentNumber, c.Version);
            IMovementStateCreated e = NewMovementStateCreated(stateEventId);

            NewMovementDocumentActionCommandAndExecute(c, _state, e);
            e.MovementDate           = c.MovementDate;
            e.Posted                 = c.Posted;
            e.Processed              = c.Processed;
            e.Processing             = c.Processing;
            e.DateReceived           = c.DateReceived;
            e.DocumentTypeId         = c.DocumentTypeId;
            e.IsInTransit            = c.IsInTransit;
            e.IsApproved             = c.IsApproved;
            e.ApprovalAmount         = c.ApprovalAmount;
            e.ShipperId              = c.ShipperId;
            e.SalesRepresentativeId  = c.SalesRepresentativeId;
            e.BusinessPartnerId      = c.BusinessPartnerId;
            e.ChargeAmount           = c.ChargeAmount;
            e.CreateFrom             = c.CreateFrom;
            e.FreightAmount          = c.FreightAmount;
            e.ReversalDocumentNumber = c.ReversalDocumentNumber;
            e.WarehouseIdFrom        = c.WarehouseIdFrom;
            e.WarehouseIdTo          = c.WarehouseIdTo;
            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 (ICreateMovementLine innerCommand in c.MovementLines)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IMovementLineStateCreated innerEvent = MapCreate(innerCommand, c, version, _state);
                e.AddMovementLineEvent(innerEvent);
            }


            return(e);
        }
Ejemplo n.º 4
0
        public virtual MovementStateCreatedDto ToMovementStateCreatedDto(IMovementStateCreated e)
        {
            var dto = new MovementStateCreatedDto();

            dto.MovementEventId        = e.MovementEventId;
            dto.CreatedAt              = e.CreatedAt;
            dto.CreatedBy              = e.CreatedBy;
            dto.CommandId              = e.CommandId;
            dto.DocumentStatusId       = e.DocumentStatusId;
            dto.MovementDate           = e.MovementDate;
            dto.Posted                 = e.Posted;
            dto.Processed              = e.Processed;
            dto.Processing             = e.Processing;
            dto.DateReceived           = e.DateReceived;
            dto.DocumentTypeId         = e.DocumentTypeId;
            dto.IsInTransit            = e.IsInTransit;
            dto.IsApproved             = e.IsApproved;
            dto.ApprovalAmount         = e.ApprovalAmount;
            dto.ShipperId              = e.ShipperId;
            dto.SalesRepresentativeId  = e.SalesRepresentativeId;
            dto.BusinessPartnerId      = e.BusinessPartnerId;
            dto.ChargeAmount           = e.ChargeAmount;
            dto.CreateFrom             = e.CreateFrom;
            dto.FreightAmount          = e.FreightAmount;
            dto.ReversalDocumentNumber = e.ReversalDocumentNumber;
            dto.WarehouseIdFrom        = e.WarehouseIdFrom;
            dto.WarehouseIdTo          = e.WarehouseIdTo;
            dto.Description            = e.Description;
            dto.Active                 = e.Active;
            var movementLineEvents = new List <MovementLineStateCreatedDto>();

            foreach (var ee in e.MovementLineEvents)
            {
                MovementLineStateCreatedDto eeDto = MovementLineStateEventDtoConverter.ToMovementLineStateCreatedDto(ee);
                movementLineEvents.Add(eeDto);
            }
            dto.MovementLineEvents = movementLineEvents.ToArray();

            return(dto);
        }
Ejemplo n.º 5
0
        public virtual void Create(ICreateMovement c)
        {
            IMovementStateCreated e = Map(c);

            Apply(e);
        }
Ejemplo n.º 6
0
        protected void NewMovementDocumentActionCommandAndExecute(ICreateMovement c, IMovementState s, IMovementStateCreated e)
        {
            var pCommandHandler = this.MovementDocumentActionCommandHandler;
            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);
        }
Ejemplo n.º 7
0
 void IMovementState.When(IMovementStateCreated e)
 {
     throw new NotSupportedException();
 }