12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System.Transactions;
- using Microsoft.AspNetCore.Mvc;
- using UnivateProperties_API.Containers.Timeshare.Detailed;
- using UnivateProperties_API.Model.Users;
- using UnivateProperties_API.Repository;
- using UnivateProperties_API.Repository.Users;
-
- namespace User_API.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class IndividualController : ControllerBase
- {
- private readonly IRepository<Individual> _Repo;
-
- public IndividualController(IRepository<Individual> 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));
- }
-
- [HttpGet("getIndividual/{id}")]
- public IActionResult GetIndividual(int id)
- {
- return new OkObjectResult((_Repo as IndividualRepository).GetIndividual(id));
- }
-
- [HttpGet("getAllIndividuals")]
- public IActionResult GetAllIndividuals()
- {
- return new OkObjectResult((_Repo as IndividualRepository).GetAllIndividuals());
- }
-
- [HttpPut()]
- public IActionResult Put([FromBody]DetailedOwner owner)
- {
- if (owner != null)
- {
- using (var scope = new TransactionScope())
- {
- (_Repo as IndividualRepository).Update(owner);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
- }
- }
|