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 IndividualController : ControllerBase { private readonly IRepository _Repo; public IndividualController(IRepository repo) { _Repo = repo; } //Gets data from the DB [HttpGet] public IActionResult Get() { return new OkObjectResult(_Repo.GetAll()); } //Gets data from DB by Id [HttpGet("{id}")] public IActionResult Get(int id) { return new OkObjectResult(_Repo.Get(x => x.Id == id)); } //Updates to DB [HttpPut()] public IActionResult Put([FromBody] Individual individual) { if (individual != null) { using (var scope = new TransactionScope()) { _Repo.Update(individual); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } //Updates DB by removing said Id [HttpDelete("{id}")] public IActionResult Delete(int id) { _Repo.RemoveAtId(id); return new OkResult(); } } }