Example #1
0
        public IActionResult DeleteUserByEmail(string email)
        {
            if (ds.IsUserSchoolAdmin(email))
            {
                return(BadRequest("You will not be able to delete a School Admin."));
            }
            ObjectManipulationResult deleteResult;

            using (var managementClient = new ManagementApiClient())
            {
                try
                {
                    var DbUser = ds.GetUserByEmail(email);
                    if (DbUser != null)
                    {
                        deleteResult = ds.DeleteUser(email);
                    }
                    else
                    {
                        deleteResult = ObjectManipulationResult.Success;
                    }

                    if (deleteResult == ObjectManipulationResult.Success)
                    {
                        var Auth0user = managementClient.GetUserByEmail(email);
                        if (Auth0user != null)
                        {
                            managementClient.DeleteUser(Auth0user.UserId);
                        }
                    }
                }
                catch (IndexOutOfRangeException ie)
                {
                    deleteResult = ObjectManipulationResult.NotFound;
                }
                catch (Exception e)
                {
                    deleteResult = ObjectManipulationResult.ErrorOccured;
                }
            }

            if (deleteResult == ObjectManipulationResult.ErrorOccured)
            {
                return(StatusCode(500, "Error occured while deleting this user!"));
            }

            if (deleteResult == ObjectManipulationResult.Exists)
            {
                return(StatusCode(409, "You can't delete main school admin!"));
            }

            return(NoContent());
        }
Example #2
0
 public IActionResult InviteUser(string email)
 {
     using (var managementClient = new ManagementApiClient())
     {
         var userAuth0 = managementClient.GetUserByEmail(email);
         if (userAuth0 == null)
         {
             return(Ok("Varify Email didn't send. Need to Invite User"));
         }
         managementClient.RequestVerifyEmail(userAuth0.UserId);
         return(Ok(userAuth0));
     }
 }