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
        public async Task <EsUpdateJudgeCommandResponse> Handle(EsUpdateJudgeCommand request, CancellationToken cancellationToken)
        {
            var validator       = new EsUpdateJudgeCommandValidator();
            var validatorResult = await validator.ValidateAsync(request);

            if (!validatorResult.IsValid)
            {
                return(new EsUpdateJudgeCommandResponse(validatorResult));
            }

            var judgedto = _mapper.Map <JudgeDto>(request);
            var judge    = _mapper.Map <Judge>(judgedto);

            var eventstoreResult = Get <JudgeAggregate>(judge.UniqueId.GetAggregateKey());

            if (!eventstoreResult.Success)
            {
                return(await Task.FromResult(new
                                             EsUpdateJudgeCommandResponse(eventstoreResult.RemoveGeneric())));
            }

            if ((eventstoreResult.Value.Version - 1) > judge.Version)
            {
                return(new EsUpdateJudgeCommandResponse
                           (ExecutionStatus.EventStoreConcurrencyError
                               (@$ "You sended old version. Your version {judge.Version}. Should be :{eventstoreResult.Value.Version - 1}")));
            }

            eventstoreResult.Value.Update(judge);
            _sessionForEventSourcing.Commit();

            return(new EsUpdateJudgeCommandResponse());
        }
        public Task <EsDeleteJudgeCommandResponse> Handle(EsDeleteJudgeCommand request, CancellationToken cancellationToken)
        {
            var eventstoreResult = Get <JudgeAggregate>(request.
                                                        UniqueId.GetAggregateKey());

            if (!eventstoreResult.Success)
            {
                return(Task.FromResult(new
                                       EsDeleteJudgeCommandResponse(eventstoreResult.RemoveGeneric())));
            }

            eventstoreResult.Value.Delete(request.UniqueId, eventstoreResult.Value.Version);
            _sessionForEventSourcing.Commit();

            return(Task.FromResult(new EsDeleteJudgeCommandResponse()));
        }
Пример #4
0
        public async Task <EsCreateJudgeCommandResponse> Handle
            (EsCreateJudgeCommand request, CancellationToken cancellationToken)
        {
            var validator       = new EsCreateJudgeCommandValidator();
            var validatorResult = await validator.ValidateAsync(request);

            if (!validatorResult.IsValid)
            {
                return(new EsCreateJudgeCommandResponse(validatorResult));
            }

            var judge = _mapper.Map <Judge>(request);

            var item = new JudgeAggregate(judge);

            _sessionForEventSourcing.Add <JudgeAggregate>(item);
            _sessionForEventSourcing.Commit();

            var ids = _mapper.Map <IdsDto>(judge.Ids());

            return(new EsCreateJudgeCommandResponse(ids));
        }
Пример #5
0
        public async Task <ESCreateCategoryCommandResponse> Handle
            (ESCreateCategoryCommand request, CancellationToken cancellationToken)
        {
            var validator       = new ESCreateCategoryCommandValidator();
            var validatorResult = await validator.ValidateAsync(request);

            if (!validatorResult.IsValid)
            {
                return(new ESCreateCategoryCommandResponse(validatorResult));
            }

            var category = _mapper.Map <Category>(request);

            var item = new CategoryAggregate(category);

            _sessionForEventSourcing.Add <CategoryAggregate>(item);
            _sessionForEventSourcing.Commit();

            var ids = _mapper.Map <IdsDto>(category.Ids());

            return(new ESCreateCategoryCommandResponse(ids));
        }
        public async Task <EsSubmitDeveloperCommandResponse> Handle
            (EsSubmitDeveloperCommand request, CancellationToken cancellationToken)
        {
            var validator       = new EsSubmitDeveloperCommandValidator();
            var validatorResult = await validator.ValidateAsync(request);

            if (!validatorResult.IsValid)
            {
                return(new EsSubmitDeveloperCommandResponse(validatorResult));
            }

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

            var developerAgreggate = new DevloperAggregate(developer);

            _sessionForEventSourcing.Add <DevloperAggregate>(developerAgreggate);
            _sessionForEventSourcing.Commit();

            var ids = _mapper.Map <DeveloperIds>(developer.Ids());

            return(new EsSubmitDeveloperCommandResponse(ids));
        }
Пример #7
0
        public async Task <EsSubmitCallForSpeechCommandResponse> Handle
            (EsSubmitCallForSpeechCommand request, CancellationToken cancellationToken)
        {
            var validator       = new EsSubmitCallForSpeechCommandValidation();
            var validatorResult = await validator.ValidateAsync(request);

            if (!validatorResult.IsValid)
            {
                return(new EsSubmitCallForSpeechCommandResponse(validatorResult));
            }

            var csf = _mapper.Map <CallForSpeech>(request);

            var item = new CallForSpeechAggregate(csf);

            _sessionForEventSourcing.Add <CallForSpeechAggregate>(item);
            _sessionForEventSourcing.Commit();

            var ids = _mapper.Map <IdsDto>(csf.Ids());

            return(new EsSubmitCallForSpeechCommandResponse(ids));
        }