/// <summary>
        ///     Validates category
        /// </summary>
        /// <param name="category">Category to validate</param>
        /// <returns>True if category is valid, false otherwise</returns>
        public void Validate(Category category)
        {
            if (category == null)
                throw new ArgumentNullException(nameof(category));

            this._validator.ValidateAndThrowCustomException(category);
        }
        public void ValidateCategory_ValidCategory_ReturnTrue()
        {
            var category = new Category
            {
                Name = "Test name",
                Description = "Test description",
                IconPath = "glyphicon-record",
                Type = CategoryType.Expense
            };

            var categoryService = new CategoryService(ProvidersFactory.GetNewTransactionsProviders());
            Assert.DoesNotThrow(() => categoryService.Validate(category));
        }
        public void ValidateCategory_EmptyName_ThrowException()
        {
            var category = new Category
            {
                Name = string.Empty,
                Description = "Test description",
                IconPath = "glyphicon-record",
                Type = CategoryType.Expense
            };

            var categoryService = new CategoryService(ProvidersFactory.GetNewTransactionsProviders());
            categoryService.Validate(category);
        }
 public async Task<bool> AddOrUpdateAsync(Category entity)
 {
     await Task.CompletedTask;
     return false;
 }
 public async Task<DeletedEntity<Category>> DeteleAsync(Category entity)
 {
     await Task.CompletedTask;
     return new DeletedEntity<Category>(null);
 }
 public Task<DeletedEntity<Category>> DeteleAsync(Category entity)
 {
     throw new NotImplementedException();
 }
 public Task<bool> AddOrUpdateAsync(Category entity)
 {
     throw new NotImplementedException();
 }
        public async Task<DeletedEntity<Category>> DeteleAsync(Category entity)
        {
            var categoryToDelete = entity.Guid == Guid.Empty
                ? null
                : await Categories.FindAsync(entity.Guid);

            Transactions.RemoveRange(categoryToDelete.Transactions);

            var deletedCategory = categoryToDelete == null
                ? null
                : Categories.Remove(categoryToDelete);

            await this.SaveChangesAsync();
            return new DeletedEntity<Category>(deletedCategory);
        }
        public async Task<bool> AddOrUpdateAsync(Category entity)
        {
            if (entity == null)
                throw new ArgumentNullException(nameof(entity));

            var existingCategory = entity.Guid == Guid.Empty
                ? null
                : await Categories.FindAsync(entity.Guid);

            Categories.AddOrUpdate(x => x.Guid, entity);

            await this.SaveChangesAsync();
            return existingCategory == null;
        }
 /// <summary>
 ///     Edits category and saves it to database
 /// </summary>
 /// <param name="category">Edited category</param>
 /// ///
 /// <param name="userId">Edited category</param>
 /// <returns></returns>
 public async Task EditCategory(Category category, Guid userId)
 {
     category.User = await this.GetUserProfileById(userId);
     this.Validate(category);
     var categoryToEdit = await this.GetCategoryByGuid(category.Guid);
     categoryToEdit.Name = category.Name;
     categoryToEdit.Description = category.Description;
     categoryToEdit.IconPath = category.IconPath;
     categoryToEdit.User = category.User;
     await this._db.AddOrUpdateAsync(categoryToEdit);
 }
 /// <summary>
 ///     Creates new category - adds it to database
 /// </summary>
 /// <param name="category">New category</param>
 /// <returns></returns>
 public async Task CreateCategory(Category category, Guid userId)
 {
     category.User = await this.GetUserProfileById(userId);
     this.Validate(category);
     await this._db.AddOrUpdateAsync(category);
 }