12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using Microsoft.AspNetCore.Mvc;
- using System.Transactions;
- using UnivateProperties_API.Model.Communication;
- using UnivateProperties_API.Repository;
- using UnivateProperties_API.Repository.Communication;
-
- namespace UnivateProperties_API.Controllers.Communication
- {
- [Route("api/[controller]")]
- [ApiController]
- public class TemplateController : ControllerBase
- {
- private readonly IRepository<Template> _Repo;
-
- public TemplateController(IRepository<Template> repo)
- {
- _Repo = repo;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- var items = _Repo.GetAll();
- return new OkObjectResult(items);
- }
-
- [HttpGet("getSimple")]
- public IActionResult GetSimple()
- {
- var items = (_Repo as TemplateRepository).GetSimpleAll();
- return new OkObjectResult(items);
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- var item = _Repo.Get(x => x.Id == id);
- return new OkObjectResult(item);
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] Template item)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Insert(item);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
- }
- }
-
- [HttpPut("{id}")]
- public IActionResult Put([FromBody] Template item)
- {
- if (item != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(item);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
-
- //[HttpPost("sendTemplate/{id}")]
- //public IActionResult SendTemplate(int id)
- //{
- // using ( var scope = new TransactionScope())
- // {
- // (_Repo as TemplateRepository).SendEmailTemplate(id);
- // scope.Complete();
- // return new OkResult();
- // }
- //}
- }
- }
|