Exemple #1
0
        public async Task <IncomeDto> CreateIncomeAsync(CreateIncomeRequest request, CancellationToken cancellationToken)
        {
            var caller = CallerExtensions.LogCaller();
            var dto    = await RunAlternateRequestAndDispatchEventAsync <CreateIncomeRequest, IncomeCreateDefinition, IncomeDto, Domain.Entities.Income>(x => _transactionService.CreateIncome(x), request, caller.Method, cancellationToken);

            return(dto);
        }
Exemple #2
0
        public async Task <IHttpActionResult> CreateIncomeAsync([FromUri] int id, [FromBody] CreateIncomeRequest request, CancellationToken cancellationToken)
        {
            var url = $"{BaseUrl}/{id}/income";

            Log.Info($"CreateIncomeAsync - Url: {url}");

            var commandResult = await _transactionModule.CreateIncomeAsync(request, cancellationToken);

            return(GetResponse(commandResult));
        }
Exemple #3
0
        public async Task <CommandResult <IncomeDto> > CreateIncomeAsync(CreateIncomeRequest request, CancellationToken cancellationToken)
        {
            var parameters = new { request, cancellationToken };

            try
            {
                if (request == null)
                {
                    return(ExceptionExtensions.GetBadResponse <IncomeDto>(parameters));
                }
            }

            catch (Exception e)
            {
                return(e.GetBadResponse <IncomeDto>(parameters));
            }

            var validator        = new CreateIncomeRequestValidator();
            var validationResult = await validator.ValidateAsync(request, cancellationToken);

            if (!validationResult.IsValid)
            {
                return(validationResult.GetBadResponse <IncomeDto>(parameters));
            }

            try
            {
                var dto = await _moduleImpl.CreateIncomeAsync(request, cancellationToken);

                if (dto == null)
                {
                    return(CommandResult <IncomeDto> .NotFound());
                }

                if (dto.Errors.Any())
                {
                    return(ExceptionExtensions.GetBadResponse <IncomeDto>(dto.Errors));
                }

                return(CommandResult <IncomeDto> .Ok(dto));
            }

            catch (DomainException domainException)
            {
                //TODO: Make sure error code is displayed
                return(domainException.GetBadResponse <IncomeDto>(parameters));
            }

            catch (Exception e)
            {
                return(e.GetInternalServerErrorResponse <IncomeDto>(parameters));
            }
        }
 public async Task <ActionResult <int> > Create([FromBody] CreateIncomeRequest value)
 {
     return(await mediator.Send(value));
 }