public object GetCommentSingle(Func <IQueryable <Comment>, object> expr) { if (_roleService.AdminPower()) { new DomainException("NoPower", "对不起,没有权限!"); } return(_commentRepository.Single(expr)); }
public void AddUser(User user) { if (_roleService.AdminPower()) { if (_userRepository.CheckUserNameExist(user.UserName)) { throw new DomainException("UserName", "该用户名已经被注册。"); } else if (_userRepository.CheckEmailExist(user.Email)) { throw new DomainException("Email", "该邮箱已经被注册。"); } _userRepository.Add(user); } else { throw new DomainException("NoPower", "对不起,您没有权限进行操作。"); } }
public int AddCategory(Category category) { if (!_roleService.AdminPower()) { throw new DomainException("NoPower", "对不起,您没有权限!"); } if (string.IsNullOrEmpty(category.Name)) { throw new DomainException("Name", "分类名称不能为空!"); } if (category.Parent != null && GetCategoryById(category.Parent.CategoryId) == null) { throw new DomainException("NoCategory", "没有找到父分类!"); } if ((int)_categoryRepository.Single(query => query.Where(c => (c.Name == category.Name) && (c.Parent == category.Parent) && (c.Type == category.Type)).Count()) > 0) { throw new DomainException("NoCategory", "发现同名分类!"); } int lint = _categoryRepository.Add(category); _categoryRepository.Save(); _categorys = null; return(lint); }