public async Task <IActionResult> CreateIncome([FromBody] IncomeRequest request) { var userId = User.Claims.FirstOrDefault(c => c.Type == "id").Value; // check if user exists 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.GetBudgetAsync(request.BudgetId); if (budget == null) { return(NotFound(new ErrorResponse(new ErrorModel { Message = $"There is no budget with id: {request.BudgetId}" }))); } if (budget.UserId != userId) { return(Forbid()); } var period = await _periodService.GetPeriodAsync(request.PeriodId); if (period == null) { return(NotFound(new ErrorResponse(new ErrorModel { Message = $"There is no Period with id: {request.PeriodId} in Budget with id: {request.BudgetId}" }))); } var income = await _incomeService.NewIncomeAsync(request, userId); if (income == null) { return(BadRequest()); } var locationUri = _uriService.GetIncomeUri(income.Id); return(Created(locationUri, new Response <IncomeResponse>(_mapper.Map <IncomeResponse>(income)))); }
public async Task <IActionResult> GetBudgetPeriod([FromRoute] int budgetId, int periodId) { var userId = User.Claims.FirstOrDefault(c => c.Type == "id").Value; // check if user exists 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.GetBudgetAsync(budgetId); if (budget == null) { return(NotFound(new ErrorResponse(new ErrorModel { Message = $"There is no budget with id: {budgetId}" }))); } if (budget.UserId != userId) { return(Forbid()); } var period = await _periodService.GetPeriodAsync(periodId); if (period == null) { return(NotFound(new ErrorResponse(new ErrorModel { Message = $"There is no Period with id: {periodId} in Budget with id: {budgetId}" }))); } return(Ok(new Response <PeriodResponse>(_mapper.Map <PeriodResponse>(period)))); }