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;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
using WindowsDataCenter.Helpers;
|
using WindowsDataCenter.Helpers;
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
@ -15,15 +12,34 @@ namespace WindowsDataCenter
|
|||||||
[RoutePrefix("api/timelogs")]
|
[RoutePrefix("api/timelogs")]
|
||||||
public class TimelogController: ApiController
|
public class TimelogController: ApiController
|
||||||
{
|
{
|
||||||
|
private readonly IRepository _repo;
|
||||||
|
public TimelogController(IRepository repo)
|
||||||
|
{
|
||||||
|
if (repo == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(repo));
|
||||||
|
}
|
||||||
|
_repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
[Route("")]
|
[Route("")]
|
||||||
[CacheControl(MaxAge = 0)]
|
[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();
|
TimeLogList logList;
|
||||||
logList.CalendarWeek = calendarWeek;
|
if (calendarWeek == -1)
|
||||||
var msg = new HttpResponseMessage(HttpStatusCode.OK);
|
{
|
||||||
msg.Content = new StringContent(JsonConvert.SerializeObject(logList),Encoding.UTF8, "application/json");
|
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);
|
return ResponseMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user