public Task <EsRejectDeveloperCommandResponse> Handle(EsRejectDeveloperCommand request,
                                                              CancellationToken cancellationToken)
        {
            var developerUniqueId = _mapper.Map <DeveloperUniqueId>
                                        (request.DeveloperUniqueId);

            var aggregateDevloper = _sessionForEventSourcing.Get <DevloperAggregate>
                                        (developerUniqueId.GetAggregateKey(), null);

            if (aggregateDevloper.Version > request.Version)
            {
                return(Task.FromResult(new EsRejectDeveloperCommandResponse
                                           ($"You sended old version.Yours {request.Version}.In Event database :{aggregateDevloper.Version}", false)));
            }

            if (aggregateDevloper.Status != DeveloperStatus.New)
            {
                return(Task.FromResult(new EsRejectDeveloperCommandResponse
                                           ($"Devloper status in eventhistory is {aggregateDevloper.Status}.Can't be Rejected", false)));
            }

            var developer = _mapper.Map <Developer>(aggregateDevloper);

            developer.Status = DeveloperStatus.Rejected;

            aggregateDevloper.Rejected(developer);
            _sessionForEventSourcing.Commit();

            return(Task.FromResult(new EsRejectDeveloperCommandResponse()));
        }
Пример #2
0
 private ExecutionStatus <T> Get <T>(AggregateKey id, int?expectedVersion = null) where T : AggregateRoot
 {
     return(_sessionForEventSourcing.Get <T>(id, expectedVersion));
 }