hanyadikhetvan-dotnethf/HanyadikHetVan/Controllers/WeeklyTimeSpanController.cs

92 lines
2.7 KiB
C#

using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Interface;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
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;
}
[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;
}
}
}