Beispiel #1
0
        async public Task <List <Worker> > GetWorkersAPI() //Get workerrequest forcing update from database
        {
            //Determine max ID already pulled from server
            var internalworkers = _connection.Table <Worker>().ToListAsync().Result;
            int maxID;

            try { maxID = internalworkers.Select(c => c.WorkerID).Max(); }
            catch { maxID = 0; }


            //Pull only new entries from server
            IEnumerable <Worker> tempW = await APIServer.GetAllWorkers(maxID.ToString());

            await _connection.InsertAllAsync(tempW); //insert database entries into local db (if any)

            return(await _connection.Table <Worker>().ToListAsync());
        }
Beispiel #2
0
        //Add Individual Entries to database list
        async public Task <int> AddWorker(Worker worker)
        {
            //Determine max ID already pulled from server
            var internalcount = _connection.Table <Worker>().ToListAsync().Result;
            int maxID;

            if (internalcount.Count == 0)
            {
                maxID = 0;
            }
            else
            {
                maxID = internalcount.Select(c => c.WorkerID).Max();
            }


            //Add worker and retrieve assigned ID
            int newID = await APIServer.AddWorker(worker); //Add worker

            //No query to database for missing workers as this will be handled during app load or when new user is swiped

            if (newID == maxID + 1) //New ID reports of -1 (invalid card) and 0 (already activated card) will not be updated locally or in SQL Db
            {
                //Add worker to local database
                worker.WorkerID = newID;
                if (worker.ReferenceNFC == Globals.ServerName + "_V")
                {
                    worker.ReferenceNFC = worker.ReferenceNFC + newID;
                }
                await _connection.InsertAsync(worker);
            }
            if (newID > maxID + 1) //Missing entries added by another user
            {
                IEnumerable <Worker> tempW = await APIServer.GetAllWorkers(maxID.ToString());

                await _connection.InsertAllAsync(tempW);
            }
            return(newID);
        }