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.

MailController.cs 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Microsoft.AspNetCore.Mvc;
  2. using RestSharp;
  3. using UnivateProperties_API.Model.Communication;
  4. using UnivateProperties_API.Repository.Communication;
  5. namespace UnivateProperties_API.Controllers.Communication
  6. {
  7. [Route("api/[controller]")]
  8. [ApiController]
  9. public class MailController : ControllerBase
  10. {
  11. private readonly IMailRepository _repo;
  12. public MailController(IMailRepository repo)
  13. {
  14. _repo = repo;
  15. }
  16. [HttpPost("{id}")]
  17. public IActionResult Post(int id, [FromBody] MailModel mm)
  18. {
  19. try
  20. {
  21. switch (id)
  22. {
  23. case 0:
  24. _repo.ContactUs(mm);
  25. break;
  26. case 1:
  27. _repo.EnquireNow(mm);
  28. break;
  29. }
  30. return new OkResult();
  31. }
  32. catch
  33. {
  34. return new BadRequestResult();
  35. }
  36. }
  37. [HttpPost("mailrecipient")]
  38. public IActionResult AddMailRecipient([FromBody] MailRecipient rec)
  39. {
  40. try
  41. {
  42. _repo.AddRecipient(rec);
  43. return new OkResult();
  44. }
  45. catch
  46. {
  47. return new BadRequestResult();
  48. }
  49. }
  50. [HttpGet("mailrecipients")]
  51. public IActionResult GetMailRecipients()
  52. {
  53. var recipients = _repo.GetMailRecipients();
  54. return new OkObjectResult(recipients);
  55. }
  56. [HttpGet("getContactLog")]
  57. public IActionResult GetContactUsLog()
  58. {
  59. var recipients = _repo.GetContactUsLog();
  60. return new OkObjectResult(recipients);
  61. }
  62. [HttpGet("getEnquireLog")]
  63. public IActionResult GetEnquireNowLog()
  64. {
  65. var recipients = _repo.GetEnquireNowLog();
  66. return new OkObjectResult(recipients);
  67. }
  68. [HttpGet("mailrecipient/{id}")]
  69. public IActionResult GetRecipientById(int id)
  70. {
  71. var recipient = _repo.GetMailRecipientById(id);
  72. return new OkObjectResult(recipient);
  73. }
  74. [HttpPut("mailrecipients")]
  75. public IActionResult UpdateRecipient([FromBody] MailRecipient rec)
  76. {
  77. _repo.UpdateMailRecipient(rec);
  78. return new OkResult();
  79. }
  80. [HttpDelete("mailrecipient/{id}")]
  81. public IActionResult DeleteRecipient(int id)
  82. {
  83. _repo.DeleteMailRecipient(id);
  84. return new OkResult();
  85. }
  86. }
  87. }