hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs
Torma Kristóf e430c0a08e
Some checks failed
continuous-integration/drone/push Build is failing
maybe drone is better now
2021-05-18 01:02:42 +02:00

102 lines
3.3 KiB
C#

using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers
{
[Route("api/weeklytimespans")]
[ApiController]
public class WeeklyTimeSpanController
{
private readonly WeeklyTimeSpanService _weeklytimespanService;
public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService)
{
_weeklytimespanService = weeklytimespanService;
}
[HttpPost]
public async Task<Object> AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan)
{
try
{
var obj = await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan);
return obj;
}
catch (Exception)
{
return false;
}
}
[HttpDelete("{weeklyTimeSpanId}")]
public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId)
{
return _weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId);
}
[HttpPut]
public bool UpdateWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan)
{
try
{
_weeklytimespanService.UpdateWeeklyTimeSpan(weeklytimespan);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpGet("date/{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 GetWeeklyTimeSpanById(int weeklytimespanId)
{
var data = _weeklytimespanService.GetWeeklyTimeSpan(weeklytimespanId);
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
);
return json;
}
[HttpGet("pauses/{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;
}
}
}