TimelogController now pulls in the Repository interface.

Implemented the GetTimeLogs method to get the proper time logs from the DB.
This commit is contained in:
chris.watts90@outlook.com 2017-02-08 22:25:21 +00:00
parent 24d35d24d2
commit 526aca3d58

View File

@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using WindowsDataCenter.Helpers;
using Interfaces;
@ -15,15 +12,34 @@ namespace WindowsDataCenter
[RoutePrefix("api/timelogs")]
public class TimelogController: ApiController
{
private readonly IRepository _repo;
public TimelogController(IRepository repo)
{
if (repo == null)
{
throw new ArgumentNullException(nameof(repo));
}
_repo = repo;
}
[Route("")]
[CacheControl(MaxAge = 0)]
public IHttpActionResult GetTimeLogs([FromUri]int userId, [FromUri]int calendarWeek)
public IHttpActionResult GetTimeLogs([FromUri]int userId, [FromUri] int calendarWeek = -1, [FromUri] int year = -1)
{
var logList = new TimeLogList();
logList.CalendarWeek = calendarWeek;
var msg = new HttpResponseMessage(HttpStatusCode.OK);
msg.Content = new StringContent(JsonConvert.SerializeObject(logList),Encoding.UTF8, "application/json");
TimeLogList logList;
if (calendarWeek == -1)
{
logList = _repo.GetTimeLogs(userId);
}
else
{
logList = _repo.GetTimeLogs(userId, calendarWeek);
}
var msg = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonConvert.SerializeObject(logList), Encoding.UTF8, "application/json")
};
return ResponseMessage(msg);
}
}