public int DeleteUser(int userId) { var user = _userRepository.GetUser(userId); if (user == null) { throw new ArgumentException("no such user"); } foreach (var siteId in user.GetAppRole().GetSiteIds()) { var pair = user.GetAppRole().GetRole(siteId); if (pair != null && Role.Master.Match(pair.GetFlag())) { throw new Exception("Can't delete web master."); } } var firstUserId = _userQuery.GetFirstUserId(); var total = _archiveRep.TransferArchives(userId, firstUserId); return(_userRepository.DeleteUser(user.GetAggregaterootId())); }