Exemplo n.º 1
0
        private void ActivateIdCmd(ActivateId cmd)
        {
            // ensure id exists
            if (!State.IdExists(cmd.Id))
            {
                Sender.Tell(new ActivateId_IdNotFound());
                return;
            }

            // ensure id inactive
            if (State.IdsActive.Contains(cmd.Id) ||
                State.IdsDeletedActive.Contains(cmd.Id))
            {
                Sender.Tell(new ActivateId_IdAlreadyActive());
                return;
            }

            // activate id
            var activatedId = new ActivatedId(cmd.Id);

            PersistAndTrack(activatedId, result =>
            {
                ActivatedIdEvnt(result);
                Sender.Tell(new ActivateId_Success());
            });
        }
Exemplo n.º 2
0
        private void UndeleteByIdCmd(UndeleteById cmd)
        {
            // verify id valid
            if (!State.IdDeleted(cmd.Id))
            {
                if (State.IdNotDeleted(cmd.Id))
                {
                    Sender.Tell(new UndeleteById_IdNotDeleted());
                }
                else
                {
                    Sender.Tell(new UndeleteById_IdNotFound());
                }

                return;
            }

            IActorRef entityActor = ActorRefs.Nobody;

            if (State.IdsDeletedActive.Contains(cmd.Id))
            {
                entityActor = Context.Child(cmd.Id);
                if (entityActor == ActorRefs.Nobody)
                {
                    entityActor = CreateEntity(cmd.Id);
                }
            }

            // if inactive, activate
            if (entityActor == ActorRefs.Nobody && State.IdsDeletedInactive.Contains(cmd.Id))
            {
                entityActor = CreateEntity(cmd.Id);
                var activatedId = new ActivatedId(cmd.Id);
                PersistAndTrack(activatedId, result =>
                {
                    ActivatedIdEvnt(result);
                });
            }

            // undelete record
            var undeletedId = new UndeletedId(cmd.Id);

            PersistAndTrack(undeletedId, result =>
            {
                UndeletedIdEvnt(result);
                entityActor.Forward(cmd);
            });
        }
Exemplo n.º 3
0
        private void GetByIdCmd(GetById cmd)
        {
            // verify id valid
            if (!State.IdNotDeleted(cmd.Id))
            {
                if (State.IdDeleted(cmd.Id))
                {
                    Sender.Tell(new GetById_IdDeleted());
                }
                else
                {
                    Sender.Tell(new GetById_IdNotFound());
                }

                return;
            }


            IActorRef childActor = Context.Child(cmd.Id);

            // if inactive, activate
            if (State.IdsInactive.Contains(cmd.Id))
            {
                var activatedId = new ActivatedId(cmd.Id);
                PersistAndTrack(activatedId, result =>
                {
                    ActivatedIdEvnt(result);
                    if (childActor == ActorRefs.Nobody)
                    {
                        childActor = CreateEntity(cmd.Id);
                    }
                });
            }

            // return model for id
            childActor.Forward(cmd);

            // leave child active
        }
Exemplo n.º 4
0
 private void ActivatedIdEvnt(ActivatedId evnt)
 {
     State.ActivateId(evnt.Id);
 }