Example #1
0
        async public Task <int> AddVessel(Vessel vessel)
        {
            //Determine max ID already pulled from server
            var internalcount = _connection.Table <Vessel>().ToListAsync().Result;
            int maxID;

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

            //Add vessel and retrieve assigned ID
            int newID = await APIServer.AddVessel(vessel);

            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
                vessel.VesselID = newID;
                await _connection.InsertAsync(vessel);
            }
            if (newID > maxID + 1) //Missing entries added by another user
            {
                IEnumerable <Vessel> tempV = await APIServer.GetAllVessels(maxID.ToString());

                await _connection.InsertAllAsync(tempV);
            }

            return(newID);
        }
Example #2
0
        async public Task <List <Vessel> > GetVesselsAPI() //Get workerrequest forcing update from database
        {
            //Determine max ID already pulled from server
            var internalvessels = _connection.Table <Vessel>().ToListAsync().Result;
            int maxID;

            try { maxID = internalvessels.Select(c => c.VesselID).Max(); }
            catch { maxID = 0; }

            //Pull only new entries from server
            IEnumerable <Vessel> tempV = await APIServer.GetAllVessels(maxID.ToString());

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

            return(await _connection.Table <Vessel>().ToListAsync());
        }