1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using Microsoft.AspNetCore.Mvc;
- using RestSharp;
- using UnivateProperties_API.Model.Communication;
- using UnivateProperties_API.Repository.Communication;
-
- namespace UnivateProperties_API.Controllers.Communication
- {
- [Route("api/[controller]")]
- [ApiController]
- public class MailController : ControllerBase
- {
- private readonly IMailRepository _repo;
- public MailController(IMailRepository repo)
- {
- _repo = repo;
- }
-
- [HttpPost("{id}")]
- public IActionResult Post(int id, [FromBody] MailModel mm)
- {
- try
- {
- switch (id)
- {
- case 0:
- _repo.ContactUs(mm);
- break;
- case 1:
- _repo.EnquireNow(mm);
- break;
- }
- return new OkResult();
- }
- catch
- {
- return new BadRequestResult();
- }
- }
-
- [HttpPost("mailrecipient")]
- public IActionResult AddMailRecipient([FromBody] MailRecipient rec)
- {
- try
- {
- _repo.AddRecipient(rec);
- return new OkResult();
- }
- catch
- {
- return new BadRequestResult();
- }
-
- }
-
- [HttpGet("mailrecipients")]
- public IActionResult GetMailRecipients()
- {
- var recipients = _repo.GetMailRecipients();
- return new OkObjectResult(recipients);
- }
-
- [HttpGet("mailrecipient/{id}")]
- public IActionResult GetRecipientById(int id)
- {
- var recipient = _repo.GetMailRecipientById(id);
- return new OkObjectResult(recipient);
- }
-
- [HttpPut("mailrecipients")]
- public IActionResult UpdateRecipient([FromBody] MailRecipient rec)
- {
- _repo.UpdateMailRecipient(rec);
- return new OkResult();
- }
-
- [HttpDelete("mailrecipient/{id}")]
- public IActionResult DeleteRecipient(int id)
- {
- _repo.DeleteMailRecipient(id);
- return new OkResult();
- }
- }
- }
|