コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task <IActionResult> CreateAsync(
            [FromBody] TransactionCategoryCreateDto transactionCategoryCreateDto)
        {
            int id = await this.transactionCategoryService.CreateAsync(transactionCategoryCreateDto);

            return(this.Ok(new { Id = id }));
        }