Exemplo n.º 1
0
        // Save user id on device to use it later
        async void LoginIsSuccessful(UsersModel user)
        {
            // Add the logged in user into local table
            if (await userRepository.AddUser(user) == 0)
            {
                //DisplayAlertMessage(userRepository.Message);
                return;
            }

            // Set Shared User Defaults
            var plist = NSUserDefaults.StandardUserDefaults;

            plist.SetBool(true, "isUserLoggedIn"); // set flag that user logged in
            plist.SetString(user.Id, "userId");

            // Set user settings
            UserSettings.DefaultSettings.SetSettings();

            // Create Table Prompts and load data from the remote server
            var promptRepository = new PromptsRepository();
            await promptRepository.GetTablePrompts();

            // After login, get full table "user_prompts" from remote database and insert it in local database
            var userPromptRepository = new UsersPromptsRepository();
            await userPromptRepository.SyncAllTableUserPrompts(user.Id);

            // Remove overlay
            LoadingOverlay.RemoveOverlay();

            // Create an instance of AppDelegate and call SetRootViewController method to display MainTabBarController after successfu login
            var appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;

            appDelegate.SetRootViewController(true);
        }
Exemplo n.º 2
0
        // Get prompts in background mode
        public async override void PerformFetch(UIApplication application, Action <UIBackgroundFetchResult> completionHandler)
        {
            //Return no new data by default
            var result = UIBackgroundFetchResult.NoData;

            try
            {
                // Check for new data, and display it
                var    userPromptRepository = new UsersPromptsRepository();
                string userId = NSUserDefaults.StandardUserDefaults.StringForKey("userId");

                var newPrompt = userPromptRepository.GenerateNewPrompt(userId);
                // If prompt succesfully generated, display it in collection view and show notification
                if (newPrompt.Any())
                {
                    AppNotifications.Display(newPrompt.First());
                    await userPromptRepository.SyncCurrentUserPrompts(userId);

                    // Inform system of fetch results
                    result = UIBackgroundFetchResult.NewData;
                }
                else
                {
                    //AppNotifications.Display(new DisplayedPromptsModel() { Category = "", Task = "There is no any prompt to display" });
                    completionHandler(UIBackgroundFetchResult.NoData);
                }
            }
            catch
            {
                //Indicate a failed fetch if there was an exception
                result = UIBackgroundFetchResult.Failed;
            }
            finally
            {
                completionHandler(result);
            }
        }