public IActionResult Post([FromBody] TaskLogAPI item) { if (item == null) { return(BadRequest()); } TaskLog TaskLog = TaskLogAPI.To(item); try { TaskLog = new TaskLogBF(DB).Create(TaskLog); return(CreatedAtRoute( "TaskLogRoute", new { controller = "TaskLog", id = TaskLog.ID }, TaskLogAPI.From(TaskLog))); } catch (Exception ex) { return(BadRequest(ex)); } }
public IActionResult Get(long id) { TaskLog item = new TaskLogBF(DB).Get(id); if (item == null) { return(NotFound()); } else { return(new ObjectResult(TaskLogAPI.From(item))); } }
public IActionResult Put(long id, [FromBody] TaskLogAPI item) { if (item == null) { return(BadRequest()); } try { TaskLog updateItem = new TaskLogBF(DB).Update(TaskLogAPI.To(item)); return(new ObjectResult(TaskLogAPI.From(updateItem))); } catch (Exception ex) { return(BadRequest(ex)); } }
public void Test5() { using (JobLoggerDbContext db = new JobLoggerDbContext()) { int featureCount = db.Features.ToArray().Count(); int requirementCount = db.Requirements.ToArray().Count(); int taskCount = db.Tasks.ToArray().Count(); int taskLogCount = db.TaskLogs.ToArray().Count(); int checkInCount = db.CheckIns.ToArray().Count(); int taskCheckInCount = db.TaskCheckIns.ToArray().Count(); Feature feature = new Feature { ID = 3, Title = "Feature Number 3", Status = RequirementStatus.Active, Requirements = new List <Requirement> { new Requirement { ID = 4, Title = "Requirement Number 4", Status = RequirementStatus.Active, Tasks = new List <Task> { new Task { ID = 8, Title = "Task Number 8", TaskType = TaskType.Task, IsActive = true } } } } }; feature = new FeatureBF(db).Create(feature); Assert.AreEqual(featureCount + 1, db.Features.ToArray().Count()); Assert.AreEqual(requirementCount + 1, db.Requirements.ToArray().Count()); Assert.AreEqual(taskCount + 1, db.Tasks.ToArray().Count()); Assert.AreEqual(taskLogCount, db.TaskLogs.ToArray().Count()); Assert.AreEqual(checkInCount, db.CheckIns.ToArray().Count()); Assert.AreEqual(taskCheckInCount, db.TaskCheckIns.ToArray().Count()); TaskLog newTaskLog = new TaskLog { LogDate = DateTime.Parse("1-July-2019"), StartTime = TimeSpan.Parse("08:30"), EndTime = TimeSpan.Parse("10:15"), Description = "TaskLog Number 1", TaskID = 8 }; newTaskLog = new TaskLogBF(db).Create(newTaskLog); Assert.AreEqual(featureCount + 1, db.Features.ToArray().Count()); Assert.AreEqual(requirementCount + 1, db.Requirements.ToArray().Count()); Assert.AreEqual(taskCount + 1, db.Tasks.ToArray().Count()); Assert.AreEqual(taskLogCount + 1, db.TaskLogs.ToArray().Count()); Assert.AreEqual(checkInCount, db.CheckIns.ToArray().Count()); Assert.AreEqual(taskCheckInCount, db.TaskCheckIns.ToArray().Count()); CheckIn newCheckIn = new CheckIn { ID = 1, CheckInTime = DateTime.Parse("1-July-2019 09:43"), Comment = "CheckIn Number 1", CodeBranchID = db.CodeBranches.Where(c => c.Name == "Code Branch 1").Single().ID, TaskCheckIns = new List <TaskCheckIn> { new TaskCheckIn { TaskID = 8 } }, TaskLog = newTaskLog }; newCheckIn = new CheckInBF(db).Create(newCheckIn); Assert.AreEqual(featureCount + 1, db.Features.ToArray().Count()); Assert.AreEqual(requirementCount + 1, db.Requirements.ToArray().Count()); Assert.AreEqual(taskCount + 1, db.Tasks.ToArray().Count()); Assert.AreEqual(taskLogCount + 1, db.TaskLogs.ToArray().Count()); Assert.AreEqual(checkInCount + 1, db.CheckIns.ToArray().Count()); Assert.AreEqual(taskCheckInCount + 1, db.TaskCheckIns.ToArray().Count()); Task fetchedTask = db.Tasks .Where(t => t.ID == 8) .Include(l => l.Logs) .ThenInclude(c => c.CheckIns) .ThenInclude(t => t.TaskCheckIns) .Single(); Assert.AreEqual(1, fetchedTask.Logs.Count()); Assert.AreEqual(1, fetchedTask.Logs.First().CheckIns.Count()); Assert.AreEqual(1, fetchedTask.Logs.First().CheckIns.First().TaskCheckIns.Count()); } }