コード例 #1
0
        async public Task <List <Unit> > GetUnitsAPI() //Get workerrequest forcing update from database
        {
            //Determine max ID already pulled from server
            var internalunits = _connection.Table <Unit>().ToListAsync().Result;
            int maxID;

            try { maxID = internalunits.Select(c => c.UnitID).Max(); }
            catch { maxID = 0; }

            //Pull only new entries from server
            IEnumerable <Unit> tempU = await APIServer.GetAllUnits(maxID.ToString());

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

            return(await _connection.Table <Unit>().ToListAsync());
        }
コード例 #2
0
        async public Task <int> AddUnit(Unit unit)
        {
            //Determine max ID already pulled from server
            var internalcount = _connection.Table <Unit>().ToListAsync().Result;
            int maxID;

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

            //Add unit and retrieve assigned ID
            int newID = await APIServer.AddUnit(unit);

            if (newID == maxID + 1) //New ID reports of -1 (unsuccessful SQL) and 0 (incorrect API request) will not be updated locally or in SQL Db
            {
                //Add worker to local database
                unit.UnitID = newID;
                await _connection.InsertAsync(unit);
            }
            if (newID > maxID + 1) //Missing entries added by another user
            {
                IEnumerable <Unit> tempU = await APIServer.GetAllUnits(maxID.ToString());

/*                _connection.DropTableAsync<Unit>().Wait();
 *              _connection.CreateTableAsync<Unit>().Wait();*/

                await _connection.InsertAllAsync(tempU);
            }

            return(newID);
        }