/// <summary>
 /// Inserts or updates profile in local table storage and syncs with mobile api
 /// </summary>
 /// <param name="profile">DataObjects.Profile to add or update</param>
 /// <returns>System.Theading.Tasks.Task</returns>
 public async Task <SyncState> AddUpdateProfile(DataObjects.Profile profile)
 {
     if (null == await profileTable.LookupAsync(profile.Id))
     {
         await profileTable.InsertAsync(profile);
     }
     else
     {
         await profileTable.UpdateAsync(profile);
     }
     return(await SyncProfile());
 }
        /// <summary>
        /// Sets Current User Data in local tables.
        /// </summary>
        /// <param name="Id">String Guid of current authorized user</param>
        /// <returns>System.Threading.Tasks.Task</returns>
        public async Task SetNewUser(string Id)
        {
            try
            {
                DataObjects.Profile defaultProfile = null;
                //New User, User should be connected to internet for sign in to work.
                //Need to sync user table to see if user already exists.
                if (string.IsNullOrEmpty(_currentUserId) || _currentUserId == Guid.Empty.ToString())
                {
                    await SyncUser();
                }
                DataObjects.User currentUser = await userTable.LookupAsync(Id);

                //If user still not found after sync need to insert new user
                if (currentUser == null || currentUser.Id != Id)
                {
                    currentUser = new DataObjects.User()
                    {
                        Id = Id, ActiveDirectoryObjectId = Id
                    };
                    await userTable.InsertAsync(currentUser);

                    defaultProfile = new DataObjects.Profile()
                    {
                        Id = Guid.NewGuid().ToString(), PrimaryUserId = currentUser.Id
                    };
                    await AddUpdateProfile(defaultProfile);
                    await SetUserDefaultProfile(currentUser.Id, defaultProfile.Id);
                    await SyncUser();
                    await SyncProfile();
                }
                else
                {
                    //User Existed In Cloud, retrieve profile
                    await SyncProfile();

                    defaultProfile = await GetProfile(currentUser.DefaultProfileId);

                    if (defaultProfile == null)
                    {
                        defaultProfile = new DataObjects.Profile()
                        {
                            Id = Guid.NewGuid().ToString(), PrimaryUserId = currentUser.Id
                        };
                        await AddUpdateProfile(defaultProfile);
                        await SetUserDefaultProfile(currentUser.Id, defaultProfile.Id);
                        await SyncUser();
                        await SyncProfile();
                    }
                }

                //Make Sure user has a profile.
                _currentUserId    = Id;
                _currentProfileId = defaultProfile.Id;
                _isLoggedIn       = true;
                await SyncPump();
                await SyncChild();
                await SyncMedia();

                await Task.WhenAll(new Task[] { SyncPresetExperiences(),
                                                SyncUserExperiences(),
                                                SyncHistoricalSessions(),
                                                SyncCaregiverRequest(),
                                                SyncCaregiverRelation() });
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            finally
            {
                OnSetUserCompleteEvent(new object());
            }
        }