public IHttpActionResult SecurityChekedInVisitor() { using (var db = new vmsDBContext()) { var task = from inout in db.InOuts where inout.Status == "Security Checkin" && (inout.OutTime.Equals(null) || inout.OutTime.Equals(string.Empty)) join vst in db.Visitors on inout.VisitorID equals vst.VisitorID into t from rt in t.DefaultIfEmpty() orderby inout.EntryDate select new { rt.Name, Vehicle = rt.Vehicle, rt.Building, rt.MeeTTo, inout.InTime, inout.OutTime, inout.Status, rt.TokenNo, rt.VisitorID }; return Ok(task.ToList()); } }
public IHttpActionResult CheckOut(int id) { using (var db = new vmsDBContext()) { InOuts inout = new InOuts(); inout.VisitorID = id; inout.InTime = GetCheckInTime(id); inout.OutTime = string.Format("{0:HH:mm tt}", DateTime.Now); inout.Status = "Security Checkout"; inout.EntryDate = DateTime.Now; db.InOuts.Add(inout); db.SaveChanges(); } using (var db = new vmsDBContext()) { var inouts = (from inout in db.InOuts where inout.VisitorID.Equals(id) && inout.Status.Equals("Security Checkin") select inout).SingleOrDefault(); inouts.OutTime = string.Format("{0:HH:mm tt}", DateTime.Now); db.SaveChanges(); } return Ok("OK"); }
public IHttpActionResult AllVisitors() { using (var db = new vmsDBContext()) { var task = from inout in db.InOuts //where inout.Status == "Lobby Checkout" join vst in db.Visitors on inout.VisitorID equals vst.VisitorID into t from rt in t.DefaultIfEmpty() orderby inout.EntryDate select new { rt.Name, Vehicle = rt.Vehicle, rt.Building, rt.MeeTTo, inout.InTime, inout.OutTime, rt.TokenNo, EntryDate = (rt.EntryDate).ToString(), inout.Status, }; return Ok(task.ToList()); } }
public HttpResponseMessage Post(VisitorModel entity) { if (ModelState.IsValid) { using(var db = new vmsDBContext()) { Visitors vstr = new Visitors(); vstr.Name = entity.Name; vstr.Guests = entity.Guests; vstr.Email = entity.Email; vstr.Phone = entity.Phone; vstr.IdCard = entity.IdCard; vstr.Vehicle = entity.Vehicle; vstr.VehicleNu = entity.VehicleNu; vstr.Color = entity.Color; vstr.ParkineZone = entity.ParkineZone; vstr.Building = entity.Building; vstr.MeeTTo = entity.MeeTTo; vstr.TokenNo = entity.TokenNo; vstr.EntryDate = DateTime.Now; db.Visitors.Add(vstr); db.SaveChanges(); //db.Entry(vstr).GetDatabaseValues(); InOuts inout = new InOuts(); inout.VisitorID = vstr.VisitorID; inout.InTime = entity.InTime; inout.Status = "Security Checkin"; inout.EntryDate = DateTime.Now; db.InOuts.Add(inout); db.SaveChanges(); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, new { entity }); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public IHttpActionResult MyVisitors(string building) { using (var db = new vmsDBContext()) { var task = from inout in db.InOuts where inout.Status == "Lobby Checkin" && inout.Status != "Lobby Checkout" join vst in db.Visitors on inout.VisitorID equals vst.VisitorID into t from rt in t.DefaultIfEmpty() where rt.Building == "TCS" orderby inout.EntryDate select new { rt.Name, Vehicle = rt.Vehicle, rt.Building, rt.MeeTTo, inout.InTime, inout.OutTime, rt.TokenNo }; return Ok(task.ToList()); } }
protected string GetCheckInTime(int id) { string strCheckInTime =""; using(var db = new vmsDBContext()) { var CheckInTime = (from inout in db.InOuts where inout.VisitorID.Equals(id) && inout.Status.Equals("Security Checkin") select inout).SingleOrDefault(); strCheckInTime = CheckInTime.InTime; } return strCheckInTime; }