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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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("mailrecipient/{id}")]
  57. public IActionResult GetRecipientById(int id)
  58. {
  59. var recipient = _repo.GetMailRecipientById(id);
  60. return new OkObjectResult(recipient);
  61. }
  62. [HttpPut("mailrecipients")]
  63. public IActionResult UpdateRecipient([FromBody] MailRecipient rec)
  64. {
  65. _repo.UpdateMailRecipient(rec);
  66. return new OkResult();
  67. }
  68. [HttpDelete("mailrecipient/{id}")]
  69. public IActionResult DeleteRecipient(int id)
  70. {
  71. _repo.DeleteMailRecipient(id);
  72. return new OkResult();
  73. }
  74. }
  75. }