public JsonResult VisitorOut(string cardNO) { //string cardID; if (cardNO != null) { cardFactory = new CardFactorys(); utility = new Utility(); var appData = db.Appointments.Where(x => (x.CardNO == cardNO) && (x.Status == "I")).FirstOrDefault(); if (appData != null) { db.Entry(appData).State = EntityState.Detached; appData.CheckedOutTime = DateTime.Now; appData.Status = "O"; var cardInfo = db.Cards.Where(x => x.CardNO == cardNO).ToList(); if (cardInfo.Count > 0) { foreach (var card in cardInfo) { var deviceInfo = db.DeviceInfoes.Where(x => x.DeviceNO == card.DeviceNO).FirstOrDefault(); if (deviceInfo != null) { unScheduleAppointmentFactory = new UnScheduleAppointmentFactorys(); result = unScheduleAppointmentFactory.SaveAppointment(appData); if (result.isSucess) { card.CardNO = null; result = cardFactory.SaveCard(card); result.message = "Checked OUT Successful."; } } else { result.message = card.DeviceNO + " Number Device Not Found!"; return(Json(result, JsonRequestBehavior.AllowGet)); } } } } else { result.isSucess = false; result.message = "No Checked IN Visitor Found Against This Card"; } } else { result.isSucess = false; result.message = "Please Punch Visitor Card"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
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)); }