Ejemplo n.º 1
0
        public async Task <IActionResult> CreateBudget([FromBody] BudgetRequest request)
        {
            var userId = User.Claims.FirstOrDefault(c => c.Type == "id").Value;

            var userExists = await _identityService.CheckIfUserExists(userId);

            if (!userExists)
            {
                return(NotFound(new ErrorResponse(new ErrorModel {
                    Message = $"There is no user with id: {userId}"
                })));
            }

            var budget = await _budgetService.NewBudgetAsync(request, userId);

            if (budget == null)
            {
                return(BadRequest(new ErrorResponse(new ErrorModel {
                    Message = "Could not create new budget"
                })));
            }

            var locationUri = _uriService.GetBudgetUri(budget.Id);

            return(Created(locationUri, new Response <BudgetResponse>(_mapper.Map <BudgetResponse>(budget))));
        }