DeleteUser.cs 664 B

12345678910111213141516171819202122232425
  1. using BelovAPI.BaseConnection;
  2. using BelovAPI.ModelBase;
  3. using Microsoft.AspNetCore.Mvc;
  4. namespace BelovAPI.Controllers
  5. {
  6. [Route("api/[controller]")]
  7. [ApiController]
  8. [ApiExplorerSettings(GroupName = "Действия с пользователем")]
  9. public class DeleteUser : Controller
  10. {
  11. ApplicationContext db = new ApplicationContext();
  12. [HttpDelete]
  13. public IActionResult Index(int id)
  14. {
  15. User user = db.User.FirstOrDefault(x => x.Id == id);
  16. db.User.Remove(user);
  17. db.SaveChanges();
  18. return Ok($"Вы успешно удалили {user}");
  19. }
  20. }
  21. }