public async Task <PreliminaryAcceptCallForSpeechCommandResponse> Handle(PreliminaryAcceptCallForSpeechCommand request, CancellationToken cancellationToken)
        {
            var cfsuniqueId = _mapper.Map <CallForSpeechUniqueId>(request.CallForSpeechUniqueId);
            var judgeId     = _mapper.Map <JudgeId>(request.JudgeId);

            var databaseOperationCfs = await _callRepository.GetByIdAsync(cfsuniqueId);

            var databaseOperationJudge = await _judegRepository.GetByIdAsync(judgeId);

            if (!databaseOperationCfs.Success)
            {
                return(new PreliminaryAcceptCallForSpeechCommandResponse(databaseOperationCfs
                                                                         .RemoveGeneric(), "CallForSpeech Problem"));
            }

            if (!databaseOperationJudge.Success)
            {
                return(new PreliminaryAcceptCallForSpeechCommandResponse(databaseOperationJudge
                                                                         .RemoveGeneric(), "Judge Problem"));
            }

            var cfs    = databaseOperationCfs.Value;
            var result = cfs.TryPreliminaryAccept(databaseOperationJudge.Value);

            if (!result.Success)
            {
                return(new PreliminaryAcceptCallForSpeechCommandResponse(result));
            }

            await _callRepository.SavePreliminaryAcceptenceAsync(cfsuniqueId, judgeId, cfs.Status);

            return(new PreliminaryAcceptCallForSpeechCommandResponse());
        }
        public async Task <GetCallForSpeechQueryHandlerResponse> Handle(GetCallForSpeechQuery request, CancellationToken cancellationToken)
        {
            ExecutionStatus <CallForSpeech> databaseOperationCfs = null;


            if (request.CallForSpeechUniqueId != null)
            {
                if (request.queryWitchDataBase == QueryWitchDataBase.WithEventSourcing)
                {
                    databaseOperationCfs = await _zEscallRepository.GetByIdAsync(request.CallForSpeechUniqueId);
                }
                else
                {
                    databaseOperationCfs = await _callRepository.GetByIdAsync(request.CallForSpeechUniqueId);
                }
            }
            else
            if (request.queryWitchDataBase == QueryWitchDataBase.WithEventSourcing)
            {
                databaseOperationCfs = await _zEscallRepository.GetByIdAsync(request.CallForSpeechId);
            }
            else
            {
                databaseOperationCfs = await _callRepository.GetByIdAsync(request.CallForSpeechId);
            }



            if (!databaseOperationCfs.Success)
            {
                return(new GetCallForSpeechQueryHandlerResponse(databaseOperationCfs
                                                                .RemoveGeneric()));
            }

            var cfsMaped = _mapper.Map <CallForSpeechViewModel>(databaseOperationCfs.Value);

            return(new GetCallForSpeechQueryHandlerResponse(cfsMaped));
        }
        public async Task <RejectCallForSpeechCommandResponse> Handle(RejectCallForSpeechCommand request, CancellationToken cancellationToken)
        {
            var cfsuniqueId = _mapper.Map <CallForSpeechUniqueId>(request.CallForSpeechUniqueId);
            var judgeId     = _mapper.Map <JudgeId>(request.JudgeId);

            var databaseOperationCfs = await _callRepository.GetByIdAsync(cfsuniqueId);

            var databaseOperationJudge = await _judegRepository.GetByIdAsync(judgeId);

            if (!databaseOperationCfs.Success)
            {
                if (databaseOperationCfs.Reason == Reason.ReturnedNull)
                {
                    return(new RejectCallForSpeechCommandResponse(ResponseStatus.NotFoundInDataBase));
                }
                if (databaseOperationCfs.Reason == Reason.Error)
                {
                    return(new RejectCallForSpeechCommandResponse(ResponseStatus.DataBaseError));
                }
            }

            if (!databaseOperationJudge.Success)
            {
                if (databaseOperationJudge.Reason == Reason.ReturnedNull)
                {
                    return(new RejectCallForSpeechCommandResponse(ResponseStatus.NotFoundInDataBase));
                }
                if (databaseOperationJudge.Reason == Reason.Error)
                {
                    return(new RejectCallForSpeechCommandResponse(ResponseStatus.DataBaseError));
                }
            }

            var cfs   = databaseOperationCfs.Value;
            var judge = databaseOperationJudge.Value;

            var result = cfs.TryReject(judge);

            if (!result.Success)
            {
                return(new RejectCallForSpeechCommandResponse(result));
            }

            await _callRepository.SaveRejectionAsync(cfsuniqueId, judgeId, cfs.Status);

            return(new RejectCallForSpeechCommandResponse());
        }
Example #4
0
        public async Task <EvaluateCallForSpeechCommandResponse> Handle(EvaluateCallForSpeechCommand request,
                                                                        CancellationToken cancellationToken)
        {
            var idc = new CallForSpeechUniqueId(request.CallForSpeechUniqueId);
            var databaseOperation = await _callRepository.GetByIdAsync(idc);

            if (databaseOperation.Success == false)
            {
                if (databaseOperation.Reason == Reason.ReturnedNull)
                {
                    return(new EvaluateCallForSpeechCommandResponse(ResponseStatus.BadQuery));
                }
                if (databaseOperation.Reason == Reason.Error)
                {
                    return(new EvaluateCallForSpeechCommandResponse(ResponseStatus.DataBaseError));
                }
            }

            //try
            //{
            //    cfs.Evaluate(_scoringRulesFactory.DefaultSet);
            //}
            //catch (Exception ex)
            //{
            //    return new EvaluateCallForSpeechCommandResponse();
            //}
            var cfs    = databaseOperation.Value;
            var result = cfs.TryEvaluate(_scoringRulesFactory.DefaultSet);

            if (!result.Success)
            {
                return(new EvaluateCallForSpeechCommandResponse(result));
            }

            var saveop = await _callRepository.SaveEvaluatationAsync(idc, cfs.ScoreResult, cfs.Status);

            if (!saveop.Success)
            {
                return(new EvaluateCallForSpeechCommandResponse(saveop));
            }

            var scoredto = _mapper.Map <ScoreDto>(cfs.ScoreResult);

            return(new EvaluateCallForSpeechCommandResponse(scoredto));
        }