using HanyadikHetVan.Data.Entities; using HanyadikHetVan.Interface; using HanyadikHetVan.Services; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Threading.Tasks; namespace HanyadikHetVan.Controllers { [Route("api/weeklytimespan")] [ApiController] public class WeeklyTimeSpanController { private readonly WeeklyTimeSpanService _weeklytimespanService; private readonly IRepository _weeklytimespan; public WeeklyTimeSpanController(IRepository weeklytimespan, WeeklyTimeSpanService weeklytimespanService) { _weeklytimespanService = weeklytimespanService; _weeklytimespan = weeklytimespan; } [HttpPost] public async Task AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) { try { await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan); return true; } catch (Exception) { return false; } } [HttpDelete("{weeklyTimeSpanId}")] public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId) { try { _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId); return true; } catch (Exception) { return false; } } [HttpPut] public bool UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan) { try { _weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan); return true; } catch (Exception) { return false; } } [HttpGet("{startTime}")] public Object GetAllWeeklyTimeSpanByStartdate(DateTime startTime) { var data = _weeklytimespanService.GetWeeklyTimeSpanByStartdate(startTime); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } [HttpGet] public Object GetAllWeeklyTimespans() { var data = _weeklytimespanService.GetAllWeeklyTimeSpans(); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } [HttpGet("{weeklytimespanId}")] public Object GetAllPausesOfTimeSpan(int weeklytimespanId) { var data = _weeklytimespanService.GetPausesOfWeeklyTimeSpan(weeklytimespanId); var json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore } ); return json; } } }