using Microsoft.AspNetCore.Mvc; using System.Transactions; using UnivateProperties_API.Containers.Timeshare; using UnivateProperties_API.Repository.Logging; namespace UnivateProperties_API.Controllers.Logging { [Route("api/[controller]")] [ApiController] public class SearchLogController : ControllerBase { private readonly ISearchLogRepository _Repo; public SearchLogController(ISearchLogRepository repo) { _Repo = repo; } [HttpGet("{type}")] public IActionResult Get(string type) { if (type.ToUpper() == "PROPERTY") return new OkObjectResult(_Repo.GetPropertySearches()); else if (type.ToUpper() == "TIMESHARE") return new OkObjectResult(_Repo.GetTimeshareSearches()); else return NoContent(); } [HttpPost] public IActionResult Post([FromBody] TimeshareSearch item) { using (var scope = new TransactionScope()) { _Repo.SaveTimeshareSearch(item); scope.Complete(); return new OkObjectResult(item); } } } }