public JsonResult VisitorBreakOut(MV_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(); //DAL.db.Appointment appInfo = new DAL.db.Appointment(); var appInfo = db.Appointments.Where(x => x.AppointmentID == appointment.AppointmentID).FirstOrDefault(); db.Entry(appInfo).State = EntityState.Detached; if (appointment.Status == "B") { //var cardInfo = cardFactory.GetFreeCard(deviceNo); appInfo.Status = appointment.Status; result = cardFactory.UnassignCard(deviceNo, appInfo.CardNO); if (result.isSucess) { unScheduleAppointmentFactory = new UnScheduleAppointmentFactorys(); appInfo.BreakOutTime = DateTime.Now; result = unScheduleAppointmentFactory.SaveAppointment(appInfo); if (result.isSucess) { result.message = "Visitor Checked Out For Break Successful."; } } else { result.message = appInfo.CardNO + " No card not found for break!!!"; } } } else { result.message = "Please Punch Visitor Card"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult EmployeeCreate(DAL.db.Employee emp, List <int> beHalfEmpList, UserModel user) { IVMS_DBEntities db = new IVMS_DBEntities(); result = new Result(); JsonResult jsonResult = new JsonResult(); EmployeeFactory = new EmployeeFactorys(); int companyID = Convert.ToInt32(dictionary[9].Id == "" ? 0 : Convert.ToInt32(dictionary[9].Id)); emp.CompanyID = companyID; emp.Status = 1; result = EmployeeFactory.SaveEmployee(emp); if (result.isSucess) { if (beHalfEmpList != null && beHalfEmpList.Count > 0) { // Self OnBehalfEmployeeID var appDataSelf = db.Employees.Where(x => x.EmployeeID == emp.EmployeeID).FirstOrDefault(); appDataSelf.OnBehalfEmployeeID = emp.EmployeeID; db.Entry(appDataSelf).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); foreach (var details in beHalfEmpList) { var appData = db.Employees.Where(x => x.EmployeeID == details).FirstOrDefault(); appData.OnBehalfEmployeeID = emp.EmployeeID; db.Entry(appData).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } if (user.UserGroupID > 0) { UserController userController = new UserController(); jsonResult = userController.CreateUserSave(user); } } return(Json(result)); }
public JsonResult VisitorForward(DAL.db.Appointment appointment, int apID) { int results = 0; result = new Result(); int EmployeeID = Convert.ToInt32(dictionary[1].Id == "" ? 0 : Convert.ToInt32(dictionary[1].Id)); //var appData = db.Appointments.Where(x => (x.EmployeeID == EmployeeID) && (x.Status == "I") && (x.AppointmentID == apID)).FirstOrDefault(); var appData = db.Appointments.Where(x => x.AppointmentID == apID).FirstOrDefault(); if (appointment.EmployeeID == appData.EmployeeID) { result.isSucess = false; result.message = "Self forward is not allowed, Please select another employee!!!"; return(Json(result, JsonRequestBehavior.AllowGet)); } appData.CheckedOutTime = DateTime.Now; appData.Status = "O"; appointment.VisitorMobile = appData.VisitorMobile; db.Entry(appData).State = System.Data.Entity.EntityState.Modified; results = db.SaveChanges(); if (results == 1) { appointment.CheckedInTime = DateTime.Now; scheduleAppointmentFactory = new ScheduleAppointmentFactorys(); result = scheduleAppointmentFactory.SaveAppointment(appointment); if (result.isSucess) { result.message = "Visitor Forward Successful."; } } return(Json(result, JsonRequestBehavior.AllowGet)); ////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 == "AP") // { // 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) // { // scheduleAppointmentFactory = new ScheduleAppointmentFactorys(); // result = scheduleAppointmentFactory.SaveAppointment(appointment); // if (result.isSucess) // { // result.message = "Visitor Forward 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"; //} }