Added HttpDelete For Users
This commit is contained in:
@@ -76,4 +76,15 @@ public class UserController : ControllerBase
|
|||||||
var users = await _usersServices.GetAllUsersAsync();
|
var users = await _usersServices.GetAllUsersAsync();
|
||||||
return Ok(users);
|
return Ok(users);
|
||||||
}
|
}
|
||||||
|
[HttpDelete("Delete-User")]
|
||||||
|
public async Task<IActionResult> DeleteUser(string id)
|
||||||
|
{
|
||||||
|
var users = await _usersServices.GetUserByIdAsync(id);
|
||||||
|
if (users == null)
|
||||||
|
return NotFound();
|
||||||
|
var result = await _usersServices.DeleteUsersAsync(id);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using survey_beta.DTOs.Create;
|
using survey_beta.DTOs.Create;
|
||||||
using survey_beta.DTOs.Default;
|
using survey_beta.DTOs.Default;
|
||||||
@@ -140,4 +141,12 @@ public class UsersServices
|
|||||||
|
|
||||||
return userDtos;
|
return userDtos;
|
||||||
}
|
}
|
||||||
|
public async Task<bool> DeleteUsersAsync(string userid)
|
||||||
|
{
|
||||||
|
var user = await _userManager.FindByIdAsync(userid);
|
||||||
|
if (user == null) return false;
|
||||||
|
var result = await _userManager.DeleteAsync(user);
|
||||||
|
if (!result.Succeeded) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user