public async Task <int> CreateAsync( TransactionCategoryCreateDto transactionCategoryCreateDto) { var user = this.loggedInUserInfoProvider.GetLoggedInUser(); var validParent = transactionCategoryCreateDto.ParentId == null || await this.transactionCategoryRepository.AnyAsync( c => c.Id == transactionCategoryCreateDto.ParentId && c.UserId == user.Id); if (!validParent) { throw new BadRequestException("Invalid parent category"); } var transactionCategory = new TransactionCategory( transactionCategoryCreateDto.Name, transactionCategoryCreateDto.iconName, transactionCategoryCreateDto.type, user.Id) { ParentId = transactionCategoryCreateDto.ParentId }; this.transactionCategoryRepository.Create(transactionCategory); await this.wmDbTransaction.CommitAsync(); return(transactionCategory.Id); }
public async Task <IActionResult> CreateAsync( [FromBody] TransactionCategoryCreateDto transactionCategoryCreateDto) { int id = await this.transactionCategoryService.CreateAsync(transactionCategoryCreateDto); return(this.Ok(new { Id = id })); }