API
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.

UserDefinedGroupController.cs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Transactions;
  2. using Microsoft.AspNetCore.Mvc;
  3. using UnivateProperties_API.Model.Properties;
  4. using UnivateProperties_API.Repository.Properties;
  5. namespace UnivateProperties_API.Controllers.Properties
  6. {
  7. [Route("api/[controller]")]
  8. [ApiController]
  9. public class UserDefinedGroupController : ControllerBase
  10. {
  11. private readonly IUserDefinedGroupRepository _Repo;
  12. public UserDefinedGroupController(IUserDefinedGroupRepository repo)
  13. {
  14. _Repo = repo;
  15. }
  16. [HttpGet]
  17. public IActionResult Get()
  18. {
  19. return new OkObjectResult(_Repo.GetAll());
  20. }
  21. [HttpGet("{id}")]
  22. public IActionResult Get(int id)
  23. {
  24. return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
  25. }
  26. [HttpPost]
  27. public IActionResult Post([FromBody] UserDefinedGroup userDefinedGroup)
  28. {
  29. using (var scope = new TransactionScope())
  30. {
  31. _Repo.Insert(userDefinedGroup);
  32. scope.Complete();
  33. return CreatedAtAction(nameof(Get), new { id = userDefinedGroup.Id }, userDefinedGroup);
  34. }
  35. }
  36. [HttpPut]
  37. public IActionResult Put([FromBody] UserDefinedGroup userDefinedGroup)
  38. {
  39. if (userDefinedGroup != null)
  40. {
  41. using (var scope = new TransactionScope())
  42. {
  43. _Repo.Update(userDefinedGroup);
  44. scope.Complete();
  45. return new OkResult();
  46. }
  47. }
  48. return new NoContentResult();
  49. }
  50. [HttpDelete("{id}")]
  51. public IActionResult Delete(int id)
  52. {
  53. _Repo.RemoveAtId(id);
  54. return new OkResult();
  55. }
  56. }
  57. }