public async Task <int> CreateExpenseCategoryAsync(ExpenseCategoryRequest newExpenseCategory)
        {
            var expenseCategory = newExpenseCategory.ToDTO();
            await _buildingManager.AddExpenseCategoryAsync(expenseCategory);

            return(expenseCategory.CategoryId);
        }
        public async Task ChangeExpenseCategoryAsync(int categoryId, ExpenseCategoryRequest newExpenseCategory)
        {
            var expenseCategory = newExpenseCategory.ToDTO();

            expenseCategory.CategoryId = categoryId;
            await _expenseManager.UpdateExpenseCategoryAsync(expenseCategory);
        }
示例#3
0
        public static ExpenseCategoryDTO ToDTO(this ExpenseCategoryRequest expense)
        {
            ExpenseCategoryDTO DTO = new ExpenseCategoryDTO();

            DTO.FormulaType = expense.FormulaType;
            DTO.IsForOwner  = expense.IsForOwner;
            DTO.Name        = expense.Name;
            return(DTO);
        }
示例#4
0
        public async Task <NewCategoryResponse> CreateDefaultCategory(ExpenseCategoryRequest request)
        {
            var categories = await _context.ExpenseCategory.Where(c => c.IsDefault == true).ToListAsync();

            var newCategory = ExpensesTrackerFactory.DefaultCategory(request.CategoryName);

            var validation = _domainService.IsValidNewCategory(newCategory, categories);

            if (validation.IsValid())
            {
                _context.ExpenseCategory.Add(newCategory);
                int result = await _context.SaveChangesAsync();

                return(new NewCategoryResponse {
                    CategoryId = newCategory.UId
                });
            }
            return(new NewCategoryResponse {
                ValidationMessage = validation.ValidationErrorMessage
            });
        }
        public async Task <IActionResult> ChangeExpenseCategory([FromRoute] int categoryId, [FromBody] ExpenseCategoryRequest expenseCategory)
        {
            await _baseInfoApplicationService.ChangeExpenseCategoryAsync(categoryId, expenseCategory);

            return(Ok());
        }
        public async Task <IActionResult> AddExpenseCategory([FromBody] ExpenseCategoryRequest expenseCategory)
        {
            var id = await _baseInfoApplicationService.CreateExpenseCategoryAsync(expenseCategory);

            return(Ok(id));
        }
示例#7
0
        internal async Task <ActionResult <NewCategoryResponse> > CreateCustomCategory(ExpenseCategoryRequest request)
        {
            var userId     = request.UserId;
            var categories = await _context.ExpenseCategory.Where(c => c.IsDefault || c.OwnerId == userId).ToListAsync();

            var newCategory = ExpensesTrackerFactory.CustomCategory(request.CategoryName, userId);

            var validation = _domainService.IsValidNewCustomCategory(newCategory, categories);

            if (validation.IsValid())
            {
                _context.ExpenseCategory.Add(newCategory);
                int result = await _context.SaveChangesAsync();

                return(new NewCategoryResponse {
                    CategoryId = newCategory.UId, UserId = newCategory.OwnerId
                });
            }
            return(new NewCategoryResponse {
                ValidationMessage = validation.ValidationErrorMessage
            });
        }
示例#8
0
 public async Task <ActionResult <NewCategoryResponse> > AddCustom([FromBody] ExpenseCategoryRequest request)
 {
     return(await _expensesCategoriesAppService.CreateCustomCategory(request));
 }