123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using Microsoft.AspNetCore.Mvc;
- using System.Transactions;
- using UnivateProperties_API.Model.Communication;
- using UnivateProperties_API.Repository;
-
- namespace UnivateProperties_API.Controllers.Communication
- {
- [Route("api/[controller]")]
- [ApiController]
- public class AccountController : ControllerBase
- {
- private readonly IRepository<SMTPAccount> _Repo;
-
- public AccountController(IRepository<SMTPAccount> repo)
- {
- _Repo = repo;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- var items = _Repo.GetAll();
- 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] SMTPAccount 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] SMTPAccount 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();
- }
- }
- }
|