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.

CampaignController.cs 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Collections.Generic;
  3. using System.Transactions;
  4. using UnivateProperties_API.Containers.Campaigns;
  5. using UnivateProperties_API.Model.Campaigns;
  6. using UnivateProperties_API.Repository;
  7. using UnivateProperties_API.Repository.Campaigns;
  8. namespace UnivateProperties_API.Controllers.Campaigns
  9. {
  10. [Route("api/[controller]")]
  11. [ApiController]
  12. public class CampaignController : ControllerBase
  13. {
  14. private readonly ICampaignRepository _Repo;
  15. public CampaignController(ICampaignRepository _repo)
  16. {
  17. _Repo = _repo;
  18. }
  19. [HttpGet]
  20. public IActionResult Get()
  21. {
  22. return new OkObjectResult(_Repo.GetAll());
  23. }
  24. [HttpGet("{id}")]
  25. public IActionResult Get(int id)
  26. {
  27. return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
  28. }
  29. [HttpGet("GetDTO/{id}")]
  30. public IActionResult GetDTO(int id)
  31. {
  32. return new OkObjectResult(_Repo.GetDTO(x => x.Id == id));
  33. }
  34. [HttpGet("GetLandingPage/{id}")]
  35. public IActionResult GetLandingPage(int id)
  36. {
  37. return new OkObjectResult(_Repo.GetCampaignHTML(id));
  38. }
  39. [HttpGet("GetCampaignItems/{id}")]
  40. public IActionResult GetCampaignItems(int id)
  41. {
  42. return new OkObjectResult(_Repo.GetCampaignItems(id));
  43. }
  44. [HttpGet("GetCampaignPlaceHolders/{id}")]
  45. public IActionResult GetCampaignPlaceHolders(int id)
  46. {
  47. return new OkObjectResult(_Repo.GetCampaignPlaceHolders(id));
  48. }
  49. [HttpPost]
  50. public IActionResult Post([FromBody] Campaign campaign)
  51. {
  52. using (var scope = new TransactionScope())
  53. {
  54. _Repo.Insert(campaign);
  55. scope.Complete();
  56. return CreatedAtAction(nameof(Get), new { id = campaign.Id }, campaign);
  57. }
  58. }
  59. [HttpPut]
  60. public IActionResult Put(Campaign campaign)
  61. {
  62. if (campaign != null)
  63. {
  64. using (var scope = new TransactionScope())
  65. {
  66. _Repo.Update(campaign);
  67. scope.Complete();
  68. return new OkResult();
  69. }
  70. }
  71. return new NoContentResult();
  72. }
  73. [HttpDelete("{id}")]
  74. public IActionResult Delete(int id)
  75. {
  76. _Repo.RemoveAtId(id);
  77. return new OkResult();
  78. }
  79. }
  80. }