public ActionResult ValidationErrorWithoutResult()
        {
            var response = new CommandResponse();

            response.AddHandledError("Validation error 1");
            response.AddHandledError("Validation error 2");

            return(HttpResponse(response));
        }
        public ActionResult <SampleClassDto> ValidationErrorWithResult()
        {
            var response = new CommandResponse();

            response.AddHandledError("Validation error 1");
            response.AddHandledError("Validation error 2");

            return(HttpResponse <SampleClassDto>(response));
        }
        /// <summary>
        /// Método principal do handler, que executa as ações necessárias para processar
        /// o comando (uso automático do MediatR)
        /// </summary>
        public async Task <CommandResponse> Handle(TCommand request, CancellationToken cancellationToken)
        {
            var response = new CommandResponse();

            //using (var session = await _context.Database.Client.StartSessionAsync())
            //{
            //    session.StartTransaction();

            try
            {
                var result = await ExecuteAsync(request);

                //await session.CommitTransactionAsync();

                response.EventData.EntityId = result.entityId;
                response.Result             = result.result;
            }
            catch (SafeException ex)
            {
                //await session.AbortTransactionAsync();
                response.AddHandledError(ex.Message);
            }
            catch (Exception ex)
            {
                //await session.AbortTransactionAsync();
                response.AddUnhandledError(ex.Message);
                StoreDiagnosticsData(request, ex);
            }

            return(response);
            //}
        }
Example #4
0
        /// <summary>
        /// Método principal do handler, que executa as ações necessárias para processar
        /// o comando (uso automático do MediatR)
        /// </summary>
        public async Task <CommandResponse> Handle(TCommand request, CancellationToken cancellationToken)
        {
            var response = new CommandResponse();

            await using var transaction = await _context.Database.BeginTransactionAsync();

            try
            {
                var result = await ExecuteAsync(request);

                await transaction.CommitAsync();

                response.EventData.EntityId = result.entityId;
                response.Result             = result.result;
            }
            catch (SafeException ex)
            {
                response.AddHandledError(ex.Message);
            }
            catch (Exception ex)
            {
                response.AddUnhandledError(ex.Message);
                StoreDiagnosticsData(request, ex);
            }

            return(response);
        }