public JsonResult VisitorBreakIn(DAL.db.Appointment appointment) { //Card card = new Card(); //string cardID = string.Empty; if (appointment.CardNO != string.Empty) { int deviceNo = 1; cardFactory = new CardFactorys(); utility = new Utility(); // Getting device Information //var empInfo = db.Employees.Where(x => x.EmployeeID == appointment.EmployeeID).FirstOrDefault(); var appInfo = db.Appointments.Where(x => x.AppointmentID == appointment.AppointmentID).FirstOrDefault(); db.Entry(appInfo).State = EntityState.Detached; if (appointment.Status == "I") { var cardInfo = cardFactory.GetFreeCard(deviceNo); if (cardInfo != null) { //cardID = cardInfo.CardID.ToString(); cardInfo.CardNO = appointment.CardNO; result = cardFactory.SaveCard(cardInfo); appInfo.CardNO = appointment.CardNO; appInfo.BreakInTime = DateTime.Now; appInfo.Status = appointment.Status; if (result.isSucess) { unScheduleAppointmentFactory = new UnScheduleAppointmentFactorys(); result = unScheduleAppointmentFactory.SaveAppointment(appInfo); if (result.isSucess) { result.message = "Visitor Checked IN From Break Successful."; } } } } } else { result.message = "Please Punch Visitor Card"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult VisitorIn(DAL.db.Appointment appointment) { int deviceNo = 1; string cardID = string.Empty; if (appointment.CardNO != string.Empty) { cardFactory = new CardFactorys(); utility = new Utility(); // Getting device Information //var empInfo = db.Employees.Where(x => x.EmployeeID == appointment.EmployeeID).FirstOrDefault(); if (appointment.Status == "I") { var cardInfo = cardFactory.GetFreeCard(deviceNo); if (cardInfo != null) { appointment.CheckedInTime = DateTime.Now; cardID = cardInfo.CardID.ToString(); //result = utility.AssignToDevice(deviceNo, cardID, appointment.CardNO); cardInfo.CardNO = appointment.CardNO; result = cardFactory.SaveCard(cardInfo); if (result.isSucess) { unScheduleAppointmentFactory = new UnScheduleAppointmentFactorys(); result = unScheduleAppointmentFactory.SaveAppointment(appointment); if (result.isSucess) { result.message = "Checked IN Successful."; } } } else { result.isSucess = false; result.message = deviceNo + " NO. Free Card Found."; } } } else { result.message = "Please Punch Visitor Card"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult VisitorInWithDevice(DAL.db.Appointment appointment) { //Card card = new Card(); string cardID = string.Empty; if (appointment.CardNO != string.Empty) { string ip = ""; int deviceNo = 0; int portNO = 0; cardFactory = new CardFactorys(); utility = new Utility(); // Getting device Information var empInfo = db.Employees.Where(x => x.EmployeeID == appointment.EmployeeID).FirstOrDefault(); var deviceInfo = db.DeviceInfoes.Where(x => x.FloorNO == empInfo.Floor).FirstOrDefault(); //var cardInfo = db.Cards.Where(x => x.CardNO == appointment.CardNO).ToList(); if (deviceInfo != null) { ip = deviceInfo.IPAddress; deviceNo = deviceInfo.DeviceNO; portNO = deviceInfo.PortNO; if (appointment.Status == "I") { result = utility.Connect(ip, deviceNo, portNO); if (result.isSucess) { var cardInfo = cardFactory.GetFreeCard(deviceNo); if (cardInfo != null) { appointment.CheckedInTime = DateTime.Now; cardID = cardInfo.CardID.ToString(); result = utility.AssignToDevice(deviceNo, cardID, appointment.CardNO); //var card = new Card { CardID = Convert.ToInt16(cardID), CardNO = appointment.CardNO, DeviceNO = deviceNo }; cardInfo.CardNO = appointment.CardNO; result = cardFactory.SaveCard(cardInfo); if (result.isSucess) { unScheduleAppointmentFactory = new UnScheduleAppointmentFactorys(); result = unScheduleAppointmentFactory.SaveAppointment(appointment); if (result.isSucess) { result.message = "Checked IN Successful."; } } } else { result.isSucess = false; result.message = deviceNo + " NO. Device Not Found."; } } else { result.message = deviceNo + " Device Not Connected."; return(Json(result, JsonRequestBehavior.AllowGet)); } } } } else { result.message = "Please Punch Visitor Card"; } return(Json(result, JsonRequestBehavior.AllowGet)); }