Esempio n. 1
0
        public dynamic Insert(FPAttLog model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.FPAttLog, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                model = _fpAttLogService.CreateObject(model, _fpUserService);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Esempio n. 2
0
        public dynamic GetDefaultInfo()
        {
            FPAttLog model = new FPAttLog();

            try
            {
                model = _fpAttLogService.GetQueryable().FirstOrDefault();
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.FPUserId,
                FPUser = model.FPUser.Name,
                model.PIN,
                model.PIN2,
                model.Time_second,
                model.DeviceID,
                model.VerifyMode,
                model.InOutMode,
                model.WorkCode,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public void OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode, int iMachineNumber, int Tag)
        {
            try
            {
                var fpMachine = _fpMachineService.GetObjectById(Tag); //GetObjectByMachineNumber(iMachineNumber);
                int pin       = int.Parse(sEnrollNumber);
                var fpUser    = _fpUserService.GetObjectByPIN(pin);
                if (fpUser != null)
                {
                    var fpAttLog = new FPAttLog()
                    {
                        DeviceID    = iMachineNumber, //1,
                        FPUserId    = fpUser.Id,
                        PIN         = pin,
                        PIN2        = fpUser.PIN2,
                        VerifyMode  = iVerifyMethod,
                        InOutMode   = iAttState,
                        WorkCode    = iWorkCode,
                        Time_second = new DateTime(iYear, iMonth, iDay, iHour, iMinute, iSecond, DateTimeKind.Local),
                    };
                    //// Convert Server local time to machine local time
                    //DateTime curutc = fpAttLog.Time_second.ToUniversalTime().AddMinutes((double)fpMachine.TimeZoneOffset);
                    //string winTZ = fpMachine.TimeZone.ToUpper(); // FPDevice.Convertion.IanaToWindows(fpMachine.TimeZone);
                    //TimeZoneInfo destTZ = TimeZoneInfo.GetSystemTimeZones().Where(x => x.Id.ToUpper() == winTZ).FirstOrDefault();
                    //DateTime curlocaltime = TimeZoneInfo.ConvertTime(curutc, destTZ);
                    //fpAttLog.Time_second = curlocaltime;

                    // Add TimeZone info to the new DateTime
                    string         winTZ  = fpMachine.TimeZone.ToUpper(); // FPDevice.Convertion.IanaToWindows(fpMachine.TimeZone);
                    TimeZoneInfo   destTZ = TimeZoneInfo.GetSystemTimeZones().Where(x => x.Id.ToUpper() == winTZ).FirstOrDefault();
                    DateTimeOffset dto    = new DateTimeOffset(fpAttLog.Time_second, destTZ.GetUtcOffset(fpAttLog.Time_second.AddMinutes((double)fpMachine.TimeZoneOffset)));
                    fpAttLog.Time_second = dto.LocalDateTime;
                    _fpAttLogService.FindOrCreateObject(fpAttLog, _fpUserService);

                    //Notify clients
                    dynamic model = new {
                        fpAttLog.Id,
                        fpAttLog.PIN,
                        fpAttLog.PIN2,
                        fpAttLog.Time_second,
                        fpAttLog.DeviceID,
                        fpAttLog.VerifyMode,
                        fpAttLog.InOutMode,
                        fpAttLog.WorkCode,
                        fpAttLog.Reserved,
                        fpAttLog.CreatedAt,
                        fpAttLog.UpdatedAt,
                    };
                    string modelstr = JsonConvert.SerializeObject(model, JSONsettings);
                    var    feedback = GlobalHost.ConnectionManager.GetHubContext <FeedbackHub>();
                    //Calls addNewRecord on all clients (javascript function)
                    feedback.Clients.All.addNewRecord(fpAttLog.FPUserId.ToString(), modelstr);
                }
            }
            finally
            {
            }
        }
Esempio n. 4
0
        public FPAttLog VHasUser(FPAttLog fpAttLog, IFPUserService _fpUserService)
        {
            FPUser fpUser = _fpUserService.GetObjectById(fpAttLog.FPUserId);

            if (fpUser == null)
            {
                fpAttLog.Errors.Add("Generic", "FPUser Tidak ada");
            }
            return(fpAttLog);
        }
Esempio n. 5
0
 public bool ValidCreateObject(FPAttLog fpAttLog, IFPAttLogService _fpAttLogService, IFPUserService _fpUserService)
 {
     VHasUser(fpAttLog, _fpUserService);
     if (!isValid(fpAttLog))
     {
         return(false);
     }
     VHasUniqueUserTime(fpAttLog, _fpAttLogService);
     return(isValid(fpAttLog));
 }
Esempio n. 6
0
        public FPAttLog FindOrCreateObject(FPAttLog fpAttLog, IFPUserService _fpUserService)
        {
            var obj = GetObjectByUserTime(fpAttLog.FPUserId, fpAttLog.Time_second);

            if (obj == null)
            {
                obj = CreateObject(fpAttLog, _fpUserService);
                obj = GetObjectById(obj.Id); // so virtual can be accessed/included
            }
            return(obj);
        }
Esempio n. 7
0
 public FPAttLog VHasUniqueUserTime(FPAttLog fpAttLog, IFPAttLogService _fpAttLogService)
 {
     if (fpAttLog.Time_second == null || fpAttLog.Time_second.Equals(DateTime.FromBinary(0)))
     {
         fpAttLog.Errors.Add("Generic", "Time_second tidak valid");
     }
     else if (_fpAttLogService.IsUserTimeDuplicated(fpAttLog))
     {
         fpAttLog.Errors.Add("Generic", "Tidak boleh ada duplikasi waktu di user yang sama");
     }
     return(fpAttLog);
 }
Esempio n. 8
0
        public string PrintError(FPAttLog obj)
        {
            string erroroutput = "";
            KeyValuePair <string, string> first = obj.Errors.ElementAt(0);

            erroroutput += first.Key + "," + first.Value;
            foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1))
            {
                erroroutput += Environment.NewLine;
                erroroutput += pair.Key + "," + pair.Value;
            }
            return(erroroutput);
        }
Esempio n. 9
0
        public dynamic Update(FPAttLog model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.FPAttLog, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpAttLogService.GetObjectById(model.Id);
                data.FPUserId    = model.FPUserId;
                data.PIN         = model.PIN;
                data.PIN2        = model.PIN2;
                data.Time_second = model.Time_second;
                data.DeviceID    = model.DeviceID;
                data.InOutMode   = model.InOutMode;
                data.VerifyMode  = model.VerifyMode;
                data.WorkCode    = model.WorkCode;
                model            = _fpAttLogService.UpdateObject(data, _fpUserService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Esempio n. 10
0
        public dynamic Delete(FPAttLog model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.FPAttLog, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Delete Record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpAttLogService.GetObjectById(model.Id);
                model = _fpAttLogService.SoftDeleteObject(data);
            }

            catch (Exception ex)
            {
                LOG.Error("Delete Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Esempio n. 11
0
        public bool isValid(FPAttLog obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Esempio n. 12
0
 public bool ValidDeleteObject(FPAttLog fpAttLog)
 {
     fpAttLog.Errors.Clear();
     return(isValid(fpAttLog));
 }
Esempio n. 13
0
 public bool ValidUpdateObject(FPAttLog fpAttLog, IFPAttLogService _fpAttLogService, IFPUserService _fpUserService)
 {
     fpAttLog.Errors.Clear();
     ValidCreateObject(fpAttLog, _fpAttLogService, _fpUserService);
     return(isValid(fpAttLog));
 }
Esempio n. 14
0
 public FPAttLog UpdateObject(FPAttLog fpAttLog, IFPUserService _fpUserService)
 {
     return(fpAttLog = _validator.ValidUpdateObject(fpAttLog, this, _fpUserService) ? _repository.UpdateObject(fpAttLog) : fpAttLog);
 }
Esempio n. 15
0
 public FPAttLog SoftDeleteObject(FPAttLog fpAttLog)
 {
     return(fpAttLog = _validator.ValidDeleteObject(fpAttLog) ?
                       _repository.SoftDeleteObject(fpAttLog) : fpAttLog);
 }
Esempio n. 16
0
        public bool IsUserTimeDuplicated(FPAttLog fpAttLog)
        {
            IQueryable <FPAttLog> objs = _repository.FindAll(x => x.FPUserId == fpAttLog.FPUserId && x.Time_second == fpAttLog.Time_second && !x.IsDeleted && x.Id != fpAttLog.Id);

            return(objs.Count() > 0 ? true : false);
        }
Esempio n. 17
0
        public bool DownloadAttLog(FPMachine fpMachine, bool ClearAfterDownload, IFPUserService _fpUserService, IFPAttLogService _fpAttLogService)
        {
            if (fpMachine == null || fpMachine.Id <= 0)
            {
                fpMachine.Errors.Add("Generic", "FingerPrint Machine ID not found!");
            }
            else
            {
                if (FPMachines.fpDevices[fpMachine.Id] == null)
                {
                    fpMachine.IsConnected = false;                                             // FPMachines.fpDevices.Add(FPMachineId, new FPDevice.ZKEvents());
                }
                else
                {
                    fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id].bIsConnected;
                }
                if (fpMachine.IsConnected == false)
                {
                    fpMachine.Errors.Add("Generic", "Please connect the device first!");
                    return(false);
                }
                bool ok = true;
                lock (FPMachines.fpDevices[fpMachine.Id]._locker)
                {
                    FPMachines.fpDevices[fpMachine.Id].Disable(); //.axCZKEM1.DisableDeviceWithTimeOut(fpMachine.MachineNumber, FPMachines.fpDevices[fpMachine.Id].DisabledTime); //.EnableDevice(fpMachine.MachineNumber, false); // Prevent user from using the device
                    try
                    {
                        //int idwErrorCode = 0;

                        int idwEnrollNumber = 0;
                        int idwVerifyMode   = 0;
                        int idwInOutMode    = 0;

                        int idwYear     = 0;
                        int idwMonth    = 0;
                        int idwDay      = 0;
                        int idwHour     = 0;
                        int idwMinute   = 0;
                        int idwSecond   = 0;
                        int idwWorkCode = 0;
                        int idwReserved = 0;

                        int iGLCount = 0;
                        int iIndex   = 0;

                        if (FPMachines.fpDevices[fpMachine.Id].axCZKEM1.ReadGeneralLogData(fpMachine.MachineNumber)) //read all the attendance records to the memory
                        {
                            while (FPMachines.fpDevices[fpMachine.Id].axCZKEM1.GetGeneralExtLogData(fpMachine.MachineNumber, ref idwEnrollNumber, ref idwVerifyMode, ref idwInOutMode,
                                                                                                    ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute, ref idwSecond, ref idwWorkCode, ref idwReserved)) //get records from the memory
                            {
                                iGLCount++;
                                var fpUser = _fpUserService.GetObjectByPIN(idwEnrollNumber);
                                if (fpUser != null)
                                {
                                    DateTimeKind dtk      = new DateTimeKind();
                                    var          fpAttLog = new FPAttLog()
                                    {
                                        DeviceID    = fpMachine.MachineNumber,
                                        FPUserId    = fpUser.Id,
                                        PIN         = idwEnrollNumber,
                                        PIN2        = fpUser.PIN2,
                                        VerifyMode  = idwVerifyMode,
                                        InOutMode   = idwInOutMode,
                                        WorkCode    = idwWorkCode,
                                        Reserved    = idwReserved,
                                        Time_second = new DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond),
                                    };
                                    //// Convert Server local time to machine local time
                                    //DateTime curutc = fpAttLog.Time_second.ToUniversalTime().AddMinutes((double)fpMachine.TimeZoneOffset);
                                    //string winTZ = fpMachine.TimeZone.ToUpper(); // FPDevice.Convertion.IanaToWindows(fpMachine.TimeZone);
                                    //TimeZoneInfo destTZ = TimeZoneInfo.GetSystemTimeZones().Where(x => x.Id.ToUpper() == winTZ).FirstOrDefault();
                                    //DateTime curlocaltime = TimeZoneInfo.ConvertTime(curutc, destTZ);
                                    //fpAttLog.Time_second = curlocaltime;

                                    // Add TimeZone info to the new DateTime
                                    string         winTZ  = fpMachine.TimeZone.ToUpper(); // FPDevice.Convertion.IanaToWindows(fpMachine.TimeZone);
                                    TimeZoneInfo   destTZ = TimeZoneInfo.GetSystemTimeZones().Where(x => x.Id.ToUpper() == winTZ).FirstOrDefault();
                                    DateTimeOffset dto    = new DateTimeOffset(fpAttLog.Time_second, destTZ.GetUtcOffset(fpAttLog.Time_second.AddMinutes((double)fpMachine.TimeZoneOffset)));
                                    fpAttLog.Time_second = dto.LocalDateTime;
                                    _fpAttLogService.FindOrCreateObject(fpAttLog, _fpUserService);
                                }
                                iIndex++;
                            }
                        }
                        int errc = FPMachines.fpDevices[fpMachine.Id].GetLastError();
                        if (errc != (int)FPDevice.ErrorCode.NoError && errc != (int)FPDevice.ErrorCode.DataNotFound)
                        {
                            fpMachine.Errors.Add("Generic", "Download Failed (Error:" + FPMachines.fpDevices[fpMachine.Id].GetErrorMsg(errc) + ")");
                            ok = false;
                        }
                        else if (ClearAfterDownload)
                        {
                            // Delete all attendance records on machine
                            if (FPMachines.fpDevices[fpMachine.Id].axCZKEM1.ClearGLog(fpMachine.MachineNumber))
                            {
                                FPMachines.fpDevices[fpMachine.Id].axCZKEM1.RefreshData(fpMachine.MachineNumber); //the data in the device should be refreshed
                            }
                        }
                    }
                    finally
                    {
                        FPMachines.fpDevices[fpMachine.Id].Enable(); //.axCZKEM1.EnableDevice(fpMachine.MachineNumber, true);
                    }
                }
                return(ok);
            }
            return(false);
        }
Esempio n. 18
0
 public FPAttLog CreateObject(FPAttLog fpAttLog, IFPUserService _fpUserService)
 {
     fpAttLog.Errors = new Dictionary <String, String>();
     return(_validator.ValidCreateObject(fpAttLog, this, _fpUserService) ? _repository.CreateObject(fpAttLog) : fpAttLog);
 }