Esempio n. 1
0
        public async Task <bool> Handle(UpdateGatewayPageAnswerRequest request, CancellationToken cancellationToken)
        {
            _auditService.StartTracking(UserAction.UpdateGatewayPageOutcome, request.UserId, request.UserName);

            var application = await _applyRepository.GetApplication(request.ApplicationId);

            var answer = await _gatewayRepository.GetGatewayPageAnswer(request.ApplicationId, request.PageId);

            var isNew = answer == null;

            if (isNew)
            {
                answer = CreateNewGatewayPageAnswer(request.ApplicationId, request.PageId);
                _auditService.AuditInsert(answer);
            }
            else
            {
                _auditService.AuditUpdate(answer);
            }

            if (answer != null)
            {
                answer.Status              = request.Status;
                answer.Comments            = request.Comments;
                answer.UpdatedAt           = DateTime.UtcNow;
                answer.UpdatedBy           = request.UserName;
                answer.ClarificationAnswer = request.ClarificationAnswer;
                if (string.IsNullOrEmpty(answer.ClarificationAnswer))
                {
                    answer.ClarificationComments = null;
                    answer.ClarificationBy       = null;
                    answer.ClarificationDate     = null;
                }
            }

            bool updatedSuccessfully;

            if (isNew)
            {
                updatedSuccessfully = await _gatewayRepository.InsertGatewayPageAnswer(answer, request.UserId, request.UserName);
            }
            else
            {
                updatedSuccessfully = await _gatewayRepository.UpdateGatewayPageAnswer(answer, request.UserId, request.UserName);
            }

            if (application.GatewayUserId != request.UserId || application.GatewayUserName != request.UserName)
            {
                _auditService.AuditUpdate(application);
                application.GatewayUserId   = request.UserId;
                application.GatewayUserName = request.UserName;
                application.UpdatedBy       = request.UserName;
                application.UpdatedAt       = DateTime.UtcNow;
                await _applyRepository.UpdateApplication(application);
            }

            _auditService.Save();

            return(updatedSuccessfully);
        }