private void RemoveUserCategories(User user)
        {
            IList <UserCategory> userCategoriesToDelete = new List <UserCategory>(user.UserCategories);

            foreach (var item in userCategoriesToDelete)
            {
                _userCategoryService.Delete(item);
            }
        }
        public JsonResult Delete(int Id)
        {
            var UserCategoryEntity = _UserCategoryService.GetById(Id);

            if (UserCategoryEntity != null)
            {
                if (UserCategoryEntity.IsSystemAdmin == true)
                {
                    return(Json(new { data = Id, success = false, ErrorsList = Resources.LocalizedText.UserCategory_Validation_IsSystemAdmin }, JsonRequestBehavior.AllowGet));
                }
                _UserCategoryService.Delete(UserCategoryEntity);
                return(Json(new { data = Id, success = true }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { data = Id, success = false, ErrorsList = Resources.LocalizedText.DeletedItemNotFound }, JsonRequestBehavior.AllowGet));
        }
        public void user_can_delete_categories_to_observe()
        {
            var category       = _categoryRepository.FindAll().FirstOrDefault();
            var favouriteLevel = _categoryFavouriteLevelRepository.FindAll().FirstOrDefault();
            var userCategory   = new UserCategory {
                User = DatabaseHelper.UserTest2A, Category = category, CategoryFavouriteLevel = favouriteLevel
            };

            _userCategoryRepository.Create(userCategory);
            _unitOfWork.Commit();

            _userCategoryService.Delete(userCategory);
            _unitOfWork.Commit();

            UserCategory userCategoryFromDb = _userCategoryRepository.FindAll().FirstOrDefault(x => x.User.Id == DatabaseHelper.UserTest2A.Id &&
                                                                                               x.Category.Id == category.Id && x.CategoryFavouriteLevel.Id == favouriteLevel.Id);

            Assert.IsNull(userCategoryFromDb, "Category for user wasn't deleted");
        }