Added HttpDelete For Users

This commit is contained in:
2025-02-02 14:29:09 +02:00
parent 2e8c61f3e3
commit 272ef7194e
2 changed files with 20 additions and 0 deletions

View File

@@ -76,4 +76,15 @@ public class UserController : ControllerBase
var users = await _usersServices.GetAllUsersAsync();
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Default;
@@ -140,4 +141,12 @@ public class UsersServices
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;
}
}