You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserController.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Transactions;
  6. using Microsoft.AspNetCore.Mvc;
  7. using ProRestaurant.Models.Accounts;
  8. using ProRestaurant.Repository.Accounts;
  9. namespace ProRestaurant.Controllers.Accounts
  10. {
  11. [Route("api/[controller]")]
  12. [ApiController]
  13. public class UserController : ControllerBase
  14. {
  15. private readonly IUserRepository repo;
  16. public UserController(IUserRepository Repo)
  17. {
  18. repo = Repo;
  19. }
  20. [HttpGet("GetCustomers")]
  21. public IActionResult GetCustomers()
  22. {
  23. return new OkObjectResult(repo.Get(u => u.SystemRole == Classes.SystemRole.Customer));
  24. }
  25. [HttpGet("{id}")]
  26. public IActionResult Get(int id)
  27. {
  28. return new OkObjectResult(repo.GetUser(id));
  29. }
  30. [HttpGet("GetUserAddress/{id}")]
  31. public IActionResult GetUserAddress(int id)
  32. {
  33. return new OkObjectResult(repo.GetUserAddress(id));
  34. }
  35. [HttpPut]
  36. public IActionResult Put([FromBody] User user)
  37. {
  38. if (user != null)
  39. {
  40. using (var scope = new TransactionScope())
  41. {
  42. repo.Update(user);
  43. scope.Complete();
  44. return new OkResult();
  45. }
  46. }
  47. return new NoContentResult();
  48. }
  49. }
  50. }