1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Transactions;
- using Microsoft.AspNetCore.Mvc;
- using UnivateProperties_API.Model.Users;
- using UnivateProperties_API.Repository;
- using UnivateProperties_API.Repository.Users;
-
- namespace User_API.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class AgencyController : ControllerBase
- {
- private readonly IRepository<Agency> _Repo;
-
- public AgencyController(IRepository<Agency> repo)
- {
- _Repo = repo;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- return new OkObjectResult(_Repo.GetAll());
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- return new OkObjectResult(_Repo.Get(x => x.Id == id));
- }
-
- [HttpPost()]
- public IActionResult Post([FromBody] Agency agency)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Insert(agency);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = agency.Id }, agency);
- }
- }
-
- [HttpPut()]
- public IActionResult Put([FromBody] Agency agency)
- {
- if (agency != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(agency);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
- }
- }
|