123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Linq;
- using System.Net;
- using System.Transactions;
- using UnivateProperties_API.Containers.Timeshare;
- using UnivateProperties_API.Model.Timeshare;
- using UnivateProperties_API.Repository;
- using UnivateProperties_API.Repository.Timeshare;
-
- namespace UnivateProperties_API.Controllers.Timeshare
- {
- [Route("api/[controller]")]
- [ApiController]
- public class TimeshareWeekController : ControllerBase
- {
- private readonly IWeekRepository _Repo;
-
- public TimeshareWeekController(IWeekRepository repo)
- {
- _Repo = repo;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- var items = (_Repo as WeekRepository).GetDtoListAll();
- return new OkObjectResult(items);
- }
-
- [HttpGet("GetTemplate")]
- public IActionResult GetTemplate()
- {
- return new OkObjectResult(new TimeshareWeekDto());
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- var item = (_Repo as WeekRepository).GetMyDetailed(x => x.Id == id);
- return new OkObjectResult(item);
- }
-
- [HttpGet("getAvailResort")]
- public IActionResult GetAvailResort()
- {
- if (_Repo is WeekRepository)
- {
- var item = (_Repo as WeekRepository).GetAvailResort();
- return new OkObjectResult(item);
- }
- else return new OkResult();
- }
-
- [HttpGet("getByResortCode/{resortCode}")]
- public IActionResult GetAvailResort(string resortCode)
- {
- if (_Repo is WeekRepository)
- {
- var item = (_Repo as WeekRepository).GetAllByResortCode(resortCode);
- return new OkObjectResult(item);
- }
- else return new OkResult();
- }
-
- [HttpGet("getMyWeek/{id}")]
- public IActionResult GetMyWeek(int id)
- {
- if (_Repo is WeekRepository)
- {
- var item = (_Repo as WeekRepository).GetMyWeeks(id);
- return new OkObjectResult(item);
- }
- else return new OkResult();
- }
-
- [HttpGet("getNeedApproval")]
- public IActionResult GetNeedApproval()
- {
- if (_Repo is WeekRepository)
- {
- var item = (_Repo as WeekRepository).GetNeedApproval();
- return new OkObjectResult(item);
- }
- else return new OkResult();
- }
-
- [HttpGet("getBy")]
- public IActionResult GetBy(WeekFilterDto week)
- {
- var item = (_Repo as WeekRepository).GetBy(week);
- return new OkObjectResult(item);
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] TimeshareWeekDto item)
- {
- try
- {
- using (var scope = new TransactionScope())
- {
- var id = _Repo.SaveNewWeek(item);
- var savedItem = _Repo.Get(x => x.Id == id).FirstOrDefault();
- scope.Complete();
- return new OkObjectResult(savedItem);
- }
- }
- catch(Exception ex)
- {
- return StatusCode((int)HttpStatusCode.InternalServerError, ex);
- }
-
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] TimeshareWeek item)
- {
- if (item != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(item);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpPut("publishOnly")]
- public IActionResult PublishOnly([FromBody] WeekDto item)
- {
- if (item != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.PublishOnly(item);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
-
- [HttpPost("verifyweek/{id}")]
- public IActionResult Post(int id)
- {
- using (var scope = new TransactionScope())
- {
- (_Repo as WeekRepository).VerifyWeek(id);
- scope.Complete();
- return new OkResult();
- }
- }
-
- [HttpPost("publishweek/{id}")]
- public IActionResult Publishweek(int id)
- {
- using (var scope = new TransactionScope())
- {
- (_Repo as WeekRepository).VerifyWeek(id);
- scope.Complete();
- return new OkResult();
- }
- }
-
- [HttpGet("getTenderWeeks")]
- public IActionResult GetTenderWeeks()
- {
- var item = (_Repo as WeekRepository).GetTenderWeeks();
- return new OkObjectResult(item);
- }
- }
- }
|