示例#1
0
        public GetPunchesResponse GetPunches(string act, string terminal_id, string date = "")
        {
            if (!Request.Headers.Contains("ApiKey"))
            {
                throw new Exception("API Key not found in header");
            }
            var apiKey = Request.Headers.GetValues("ApiKey").FirstOrDefault();

            if (!IsApiKeyValid(apiKey))
            {
                throw new Exception("API Kay is invalid");
            }
            var d            = new FingerPrintDevice(false);
            var terminalInfo = GetTerminalList().FirstOrDefault(x => x.TerminalId == terminal_id);

            if (terminalInfo == null)
            {
                throw new Exception("Terminal not found");
            }
            var res = new GetPunchesResponse();

            if (d.Connect(terminalInfo.IpAddress, Convert.ToInt32(terminalInfo.Port)))
            {
                try
                {
                    res.data = new List <Punches>();
                    var data = d.GetDataFromDevice();
                    foreach (var record in data)
                    {
                        if (record.Date.ToString("yyyy-MM-dd") == date || date.IsNullOrWhiteSpace())
                        {
                            res.data.Add(new Punches()
                            {
                                date         = record.Date.ToString("yyyy-MM-dd"),
                                time         = record.Date.ToString("hh:mm:ss"),
                                employees_id = record.IdUser,
                            });
                        }
                    }
                }
                finally
                {
                    d.Disconnect();
                }
            }
            else
            {
                throw new Exception("CannotConnectToDevice");
            }
            return(res);
        }
示例#2
0
        public GetEmployeesResponse GetEmployees(string act, string terminal_id)
        {
            if (!Request.Headers.Contains("ApiKey"))
            {
                throw new Exception("API Key not found in header");
            }
            var apiKey = Request.Headers.GetValues("ApiKey").FirstOrDefault();

            if (!IsApiKeyValid(apiKey))
            {
                throw new Exception("API Kay is invalid");
            }
            var d = new FingerPrintDevice(false);

            var terminalInfo = GetTerminalList().FirstOrDefault(x => x.TerminalId == terminal_id);

            if (terminalInfo == null)
            {
                throw new Exception("Terminal not found");
            }
            var res = new GetEmployeesResponse();

            if (d.Connect(terminalInfo.IpAddress, Convert.ToInt32(terminalInfo.Port)))
            {
                try
                {
                    res.data = d.GetEmployees();
                }
                finally
                {
                    d.Disconnect();
                }
            }
            else
            {
                throw new Exception("CannotConnectToDevice");
            }

            return(res);
        }