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:
parent
24d35d24d2
commit
526aca3d58
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user