private bool insertNewCheckFace(string code, string machineCode, string mode, string base64, DateTime dateTime, string wifiName) { // *** LINQ *** find employee by email *** database *** Employee employee = _unitOfWork.Repository <Employee>().Find(x => x.EmployeeCode == code); // *** LINQ *** find FaceMachine by machinecode *** database *** FaceScanMachine faceScanMachine = _unitOfWork.Repository <FaceScanMachine>().Find(x => x.MachineCode == machineCode); //init checkface table and notification table if (employee != null && faceScanMachine != null) { int modeData = int.Parse(mode); checkFace = new CheckFace() { Active = true, EmployeeId = employee.Id, FaceScanMachineId = faceScanMachine.Id, Mode = modeData, StoreId = faceScanMachine.StoreId, CreateTime = dateTime, Image = base64 != null ? base64 : null, Statuts = 1,//new IpWifi = wifiName }; _unitOfWork.Repository <CheckFace>().Insert(checkFace); return(_unitOfWork.Commit() > 0 ? true : false); } return(false); }
private bool insertNewNotification(CheckFace checkFace) { //find checkfaceId by empId and machineId List <CheckFace> checkFaces = _unitOfWork.Repository <CheckFace>().GetAll().Where(x => x.EmployeeId == checkFace.EmployeeId && x.FaceScanMachineId == checkFace.FaceScanMachineId).ToList(); if (checkFaces != null) { foreach (var items in checkFaces) { if (items.CreateTime == checkFace.CreateTime) { Notifications notification = new Notifications() { Active = true, EmployeeId = checkFace.EmployeeId.Value, CheckFaceId = items.Id, CreateDate = checkFace.CreateTime, Title = title, }; _unitOfWork.Repository <Notifications>().Insert(notification); return(_unitOfWork.Commit() > 0 ? true : false); } } } return(false); }
private string insertRequestInData(WorkShiftRequest request) { string json = null; // int empId = request.id; string nameWifi = request.nameWifi; string content = request.content; DateTime createTime = request.createTime; int storeId = getStoreIdByEmpId(empId); //new request CheckFace requestWorkShift = new CheckFace() { Active = true, EmployeeId = empId, StoreId = storeId, IpWifi = nameWifi, Content = content, CreateTime = createTime }; _unitOfWork.Repository <CheckFace>().Insert(requestWorkShift); json = _unitOfWork.Commit() > 0 ? "success" : "failed"; return(json); }
//check time attendance private int checkTimeAttendace(CheckFace checkFace) { // *** LINQ *** get all data workingShift by employee Id in checkFace List <WorkingShift> workings = _unitOfWork.Repository <WorkingShift>().GetAll().Where(x => x.Active == true && x.EmployeeId == checkFace.EmployeeId).ToList(); // foreach (var items in workings) { if (DateTime.Compare(items.CheckMin.Value, checkFace.CreateTime) <= 0 && DateTime.Compare(items.CheckMax.Value, checkFace.CreateTime) >= 0) { return(items.Id); } } return(-1); }
private bool updateWorkShiftAttendance(CheckFace checkFace) { int workShiftId = checkTimeAttendace(checkFace); if (workShiftId != -1) { // *** LINQ *** get row data workshift update WorkingShift working = _unitOfWork.Repository <WorkingShift>().Find(x => x.Active == true && x.Id == workShiftId); //update status - checkTime - modeAttendance working.Status = true; working.CheckInExpandTime = checkFace.CreateTime.TimeOfDay; working.ModeAttendance = checkFace.Mode; // *** LINQ *** save change data return(_unitOfWork.Commit() > 0); } return(false); }