Esempio n. 1
0
        public async Task <ExpenseDto> CreateExpenseAsync(CreateExpenseRequest request, CancellationToken cancellationToken)
        {
            var caller = CallerExtensions.LogCaller();
            var dto    = await RunAlternateRequestAndDispatchEventAsync <CreateExpenseRequest, ExpenseCreateDefinition, ExpenseDto, Domain.Entities.Expense>(x => _transactionService.CreateExpense(x), request, caller.Method, cancellationToken);

            return(dto);
        }
        public async Task <ActionResult> CreateCarExpense([FromRoute] Guid carId,
                                                          [FromBody] CreateExpenseRequest request)
        {
            var result =
                await _expenseService.CreateExpenseAsync(carId, HttpContext.GetUserId(), _mapper.Map <Expense>(request));

            return(GenerateResponse(result));
        }
Esempio n. 3
0
 public async Task CreateExpense(CreateExpenseRequest request)
 {
     await _expensesRepository.CreateExpense(
         request.Description, request.Amount,
         request.ExpenseCategoryId,
         request.ExpenseSubcategoryId,
         request.AccountId,
         request.CreateDate);
 }
Esempio n. 4
0
        public async Task <IHttpActionResult> CreateExpenseAsync([FromUri] int id, [FromBody] CreateExpenseRequest request, CancellationToken cancellationToken)
        {
            var url = $"{BaseUrl}/{id}/expense";

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

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

            return(GetResponse(commandResult));
        }
Esempio n. 5
0
        public async Task <CommandResult <ExpenseDto> > CreateExpenseAsync(CreateExpenseRequest request, CancellationToken cancellationToken)
        {
            var parameters = new { request, cancellationToken };

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

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

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

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

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

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

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

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

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

            catch (Exception e)
            {
                return(e.GetInternalServerErrorResponse <ExpenseDto>(parameters));
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([FromBody] CreateExpenseRequest expenseRequest)
        {
            var newExpenseId = Guid.NewGuid();
            var expense      = new Expense
            {
                Id        = newExpenseId,
                Title     = expenseRequest.Title,
                UserId    = HttpContext.GetUserId(),
                Value     = expenseRequest.Value,
                DateAdded = DateTime.Now,
                Tags      = expenseRequest.Tags.Select(x => new ExpenseTag {
                    ExpenseId = newExpenseId, TagName = x
                }).ToList()
            };

            await _expenseService.CreateExpenseAsync(expense);

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.Expenses.Get.Replace("{expenseId}", expense.Id.ToString());

            return(Created(locationUri, new Response <ExpenseResponse>(_mapper.Map <ExpenseResponse>(expense))));
        }
 protected async Task <HttpResponseMessage> CreateExpenseAsync(CreateExpenseRequest request)
 {
     return(await TestClient.PostAsJsonAsync(ApiRoutes.Expenses.Create, request));
 }
Esempio n. 8
0
        public async Task <ServiceResult <ExpenseResponse> > CreateExpenseAsync(CreateExpenseRequest request, string carId)
        {
            var uri = string.Format(Url, carId);

            return(await _requestSenderService.SendAuthPostRequestAsync <ExpenseResponse>(uri, request));
        }
        public async Task <IActionResult> CreateExpenseCategory([FromBody] CreateExpenseRequest request)
        {
            await _expensesService.CreateExpense(request);

            return(Ok());
        }