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.

TemplateController.cs 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Transactions;
  3. using UnivateProperties_API.Model.Communication;
  4. using UnivateProperties_API.Repository;
  5. using UnivateProperties_API.Repository.Communication;
  6. namespace UnivateProperties_API.Controllers.Communication
  7. {
  8. [Route("api/[controller]")]
  9. [ApiController]
  10. public class TemplateController : ControllerBase
  11. {
  12. private readonly IRepository<Template> _Repo;
  13. public TemplateController(IRepository<Template> repo)
  14. {
  15. _Repo = repo;
  16. }
  17. [HttpGet]
  18. public IActionResult Get()
  19. {
  20. var items = _Repo.GetAll();
  21. return new OkObjectResult(items);
  22. }
  23. [HttpGet("getSimple")]
  24. public IActionResult GetSimple()
  25. {
  26. var items = (_Repo as TemplateRepository).GetSimpleAll();
  27. return new OkObjectResult(items);
  28. }
  29. [HttpGet("{id}")]
  30. public IActionResult Get(int id)
  31. {
  32. var item = _Repo.Get(x => x.Id == id);
  33. return new OkObjectResult(item);
  34. }
  35. [HttpPost]
  36. public IActionResult Post([FromBody] Template item)
  37. {
  38. using (var scope = new TransactionScope())
  39. {
  40. _Repo.Insert(item);
  41. scope.Complete();
  42. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  43. }
  44. }
  45. [HttpPut("{id}")]
  46. public IActionResult Put([FromBody] Template item)
  47. {
  48. if (item != null)
  49. {
  50. using (var scope = new TransactionScope())
  51. {
  52. _Repo.Update(item);
  53. scope.Complete();
  54. return new OkResult();
  55. }
  56. }
  57. return new NoContentResult();
  58. }
  59. [HttpDelete("{id}")]
  60. public IActionResult Delete(int id)
  61. {
  62. _Repo.RemoveAtId(id);
  63. return new OkResult();
  64. }
  65. //[HttpPost("sendTemplate/{id}")]
  66. //public IActionResult SendTemplate(int id)
  67. //{
  68. // using ( var scope = new TransactionScope())
  69. // {
  70. // (_Repo as TemplateRepository).SendEmailTemplate(id);
  71. // scope.Complete();
  72. // return new OkResult();
  73. // }
  74. //}
  75. }
  76. }