public TaskCategoryModel AddCategory(TaskCategoryModel category) { if (IsCategoryNull(category)) { throw new Exception("Cannot be add empty category."); } if (IsCategoryPropertiesNull(category)) { throw new Exception("Cannot be add category with empty properties."); } if (GetCategories(). Where(c => c.Title. Contains(category.Title)). Count() != 0) { throw new InvalidOperationException($"Category with name {category.Title} already exists."); } var categoryEntity = _mapper.Map <TaskCategoryEntity>(category); _taskCategoryRepository.AddCategory(categoryEntity); return(category); }