public IActionResult Post([FromBody] CheckInAPI item) { if (item == null) { return(BadRequest()); } CheckIn checkIn = CheckInAPI.To(item); try { checkIn = new CheckInBF(DB).Create(checkIn); return(CreatedAtRoute( "CheckInRoute", new { controller = "CheckIn", id = checkIn.ID }, CheckInAPI.From(checkIn))); } catch (Exception ex) { return(BadRequest(ex)); } }
public IActionResult Get(long id) { CheckIn item = new CheckInBF(DB).Get(id); if (item == null) { return(NotFound()); } else { return(new ObjectResult(CheckInAPI.From(item))); } }
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()); } }