コード例 #1
0
 public string DeleteUserGroup(string id)
 {
     if (string.IsNullOrWhiteSpace(id))
     {
         throw new Exception("No user group id");
     }
     else
     {
         int?ugId = Convert.ToInt32(id);
         if (ugId.HasValue)
         {
             UserRole userRole = null;
             using (var proxy = new UserProxy())
             {
                 userRole = proxy.GetUserGroupById(ugId.Value);
                 if (userRole != null)
                 {
                     if (userRole.Users != null && userRole.Users.Count > 0)
                     {
                         proxy.DeleteUserGroup(ugId.Value);
                         return(string.Empty);
                     }
                     else
                     {
                         // Cannot delete
                         return("Cannot delete, has user");
                     }
                 }
                 else
                 {
                     throw new Exception("Invalid user id");
                 }
             }
         }
         else
         {
             throw new Exception("Invalid user id");
         }
     }
 }