/// <summary>
        /// Inserts or update the device with the given fields.
        /// </summary>
        /// <param name="gcmToken"></param>
        /// <param name="deviceId"></param>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        public async Task InsertOrUpdateDevice(string gcmToken, string deviceId, string deviceType)
        {
            DbDevice db = new DbDevice();
            DbStudent dbStudent = new DbStudent();
            Student student = dbStudent.GetStudent();
            Device device = db.GetDevice();
            if (device == null)
            {
                device = new Device();
                device.id = deviceId;
                device.token = gcmToken;
                device.tokenSent = false;
                device.deviceType = deviceType;

                if (student != null)
                {
                    device.username = student.username;
                }
                db.InsertDevice(device);
                if (student != null)
                {
                    UpdateServersDb();
                }
                return;
            }

            if (device.token != gcmToken)
            {
                device.token = gcmToken;
                device.tokenSent = false;
                if (student != null)
                {
                    device.username = student.username;
                }
                db.UpdateDevice(device);
                if (student != null)
                {
                    UpdateServersDb();
                }
                return;
            }

            if (!device.tokenSent && student != null)
            {
                if (device.username != student.username)
                {
                    device.username = student.username;
                    db.UpdateDevice(device);
                }
                UpdateServersDb();
            }
        }
        /// <summary>
        /// Inserts the Device
        /// into the database.
        /// </summary>
        /// <param name="student"></param>
        /// <returns>Returns true if the Device was inserted, returns false if a Device with the same 
        ///  primary key already exists in the table.</returns>
        public bool InsertDevice(Device device)
        {
            if (CheckIfDeviceExist(device.id))
            {
                return false;
            }

            lock (DbContext.locker)
            {
                Db.Insert(device);
            }
            return true;
        }
        /// <summary>
        /// Updates a Device, but if it doesnt already exist a new entry will be inserted into the db.
        /// </summary>
        /// <param name="device"></param>
        public void UpdateDevice(Device device)
        {
            if (CheckIfDeviceExist(device.id))
            {
                lock (DbContext.locker)
                {
                    Db.Update(device);
                }
            }

            else
            {
                lock (DbContext.locker)
                {
                    Db.Insert(device);
                }
            }
        }
 /// <summary>
 /// Deletes the Device from the database
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 public void DeleteDevice(Device device)
 {
     try
     {
         lock (DbContext.locker)
         {
             Db.Delete<Device>(device.id);
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine("DbDevice - DeleteDevice(Device device): Exception msg: " + e.Message);
         System.Diagnostics.Debug.WriteLine("DbDevice - DeleteDevice(Device device): Stack Trace: \n" + e.StackTrace);
         System.Diagnostics.Debug.WriteLine("DbDevice - DeleteDevice(Device device): End Of Stack Trace");
     }
 }