コード例 #1
0
        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");
        }
コード例 #2
0
ファイル: VisitorsController.cs プロジェクト: niisar/VMS
        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);
            }
        }