hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs

92 lines
2.7 KiB
C#
Raw Normal View History

2021-05-03 18:15:26 +02:00
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
2021-05-03 18:36:26 +02:00
using Newtonsoft.Json;
2021-05-03 18:15:26 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Controllers
{
[Route("api/weeklytimespan")]
[ApiController]
public class WeeklyTimeSpanController
{
private readonly WeeklyTimeSpanService _weeklytimespanService;
private readonly IRepository<WeeklyTimeSpan> _weeklytimespan;
public WeeklyTimeSpanController(IRepository<WeeklyTimeSpan> weeklytimespan, WeeklyTimeSpanService weeklytimespanService)
{
_weeklytimespanService = weeklytimespanService;
_weeklytimespan = weeklytimespan;
}
2021-05-03 18:36:26 +02:00
[HttpPost]
public async Task<Object> AddWeeklyTimeSpan([FromBody] WeeklyTimeSpan weeklytimespan)
{
try
{
await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpDelete]
public bool DeleteWeeklyTimeSpan(int weeklyTimeSpanId)
{
try
{
_weeklytimespanService.DeleteWeeklyTimeSpan(weeklyTimeSpanId);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpPut]
public bool UpdateWeeklyTimeSpan(WeeklyTimeSpan Object)
{
try
{
_weeklytimespanService.UpdateWeeklyTimeSpan(Object);
return true;
}
catch (Exception)
{
return false;
}
}
[HttpGet]
public Object GetAllWeeklyTimeSpanByStartdate(DateTime UserEmail)
{
var data = _weeklytimespanService.GetPersonByUserName(UserEmail);
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
}
);
return json;
}
[HttpGet]
public Object GetAllWeeklyTimespans()
{
var data = _weeklytimespanService.GetAllWeeklyTimeSpans();
var json = JsonConvert.SerializeObject(data, Formatting.Indented,
new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
}
);
return json;
}
2021-05-03 18:15:26 +02:00
}
}