public async Task<ActionResult> SignInStatus(Guid id) { CheckInViewModel model = new CheckInViewModel(); model.Incident = await db.Incidents.FindAsync(id); model.SignIns = await db .SignIns .Where(x => x.IncidentID == id) .Where(x => x.SignedOut == null) .Join(db.Members, s => s.MemberID, m => m.MemberID, (s, m) => new MemberSignIn() { Member = m, SignIn = s }) .ToListAsync(); return View(model); }
/// <summary> /// Do sign-in form for incident with the given ID /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task<ActionResult> SignIn(Guid id, Guid? memberID) { if (memberID.HasValue) { SignIn si = new SignIn() { IncidentID = id, MemberID = memberID.Value }; db.SignIns.Add(si); Member member = await db.Members.FindAsync(memberID); Helpers.SignalSignIn(id, member.LastName, member.FirstName, si.SignedIn); await db.SaveChangesAsync(); } CheckInViewModel model = new CheckInViewModel(); model.Incident = db.Incidents.Include(i => i.SignIns).FirstOrDefault(x => x.IncidentID == id); var signIns = db.SignIns .Where(x => x.IncidentID == id) .ToList(); model.SignIns = db.Members.Select<Member, MemberSignIn>(x => new MemberSignIn() { Member = x }).ToList(); foreach (var m in model.SignIns) { var si = signIns .OrderByDescending(x => x.SignedIn) .FirstOrDefault(x => x.MemberID == m.Member.MemberID); if (si != null) m.SignIn = si; } return View(model); }