public async Task UpdateCategory(int categoryId, AddUpdateCategoryDto dto)
        {
            Category category = await _dbContext.Categories.FindAsync(categoryId);

            category.Name     = dto.CategoryName;
            category.IsIncome = dto.IsIncome;

            await _dbContext.SaveChangesAsync();
        }
        public async Task <int> AddCategoryAsync(AddUpdateCategoryDto dto, int userId)
        {
            var newCategory = dto.ToEntity(userId);

            _dbContext.Categories.Add(newCategory);

            await _dbContext.SaveChangesAsync();

            return(newCategory.Id);
        }
Пример #3
0
 public static Category ToEntity(this AddUpdateCategoryDto dto, int userId) => new Category
 {
     Name     = dto.CategoryName,
     IsIncome = dto.IsIncome,
     UserId   = userId
 };