public void UpdateCategory(CategoryModel categoryModel)
        {
            categoryModel.CheckForNull(nameof(categoryModel));
            var category = _context.Categories.SingleOrDefault(c => c.ID == categoryModel.ID);

            category.CheckForNull(nameof(category), category.ID.ToString());

            category.Name = categoryModel.Name;
            category.Icon = categoryModel.Icon;

            _context.SaveChanges();
        }
        public void AddNewCategory(CategoryModel categoryModel)
        {
            categoryModel.CheckForNull(nameof(categoryModel));

            var category = _mapper.Map <CategoryModel, Category>(categoryModel);

            _context.Categories.Add(category);
            category.UserCategories.Add(new UserCategory {
                CategoryID = category.ID, UserId = category.CreatedByID
            });

            _context.SaveChanges();
        }
        public async Task <int> AddNewCategoryAsync(CategoryModel categoryModel)
        {
            categoryModel.CheckForNull(nameof(categoryModel));

            var category = _mapper.Map <CategoryModel, Category>(categoryModel);

            _context.Categories.Add(category);
            category.UserCategories.Add(new UserCategory {
                CategoryID = category.ID, UserId = category.CreatedByID
            });

            await _context.SaveChangesAsync();

            return(category.ID);
        }