Exemple #1
0
        public async static void CheckMessages()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                User loginUser = StorageManager.GetConnectionInfo().LoginUser;

                string gencall  = "/accesstoken=" + loginUser.AccessToken;
                string usercall = gencall + "/iduser="******"/message/getall" + usercall);

                servMsg.SaveAllToDBWithServerID("IDMessage");

                SQLiteConnection      conn = StorageManager.GetConnection();
                IEnumerable <Message> msgs = conn.Query <Message>("SELECT * FROM message WHERE IDUser="******" AND seen=0 ");
                var notifier = DependencyService.Get <ICrossLocalNotifications>().CreateLocalNotifier();
                foreach (Message msg in msgs)
                {
                    notifier.Notify(new LocalNotification()
                    {
                        Title      = msg.Title,
                        Text       = msg.MessageText,
                        Id         = msg.IDMessage + 30000,
                        NotifyTime = DateTime.Now,
                    });
                    msg.seen = 1;
                    conn.Update(msg);
                    await ServiceConnector.InsertServiceData <ModelService <Message> >("/message/save", msg);
                }
            }
        }
Exemple #2
0
        public async void AreCredentialsCorrect(User user)
        {
            /* COMMENTED  - FIND USER LOCALLY
             * List<User> usrs = conn.Query<User>("SELECT IdUser,FirstName,LastName,Height,Birthdate,Email,Gender,HeightType,Password, AccessToken FROM User WHERE Email ='" + user.Email + "' AND Password ='******'");
             * if (usrs.Count > 0)
             * {
             *  PerformLogin(usrs[0]);
             *  return;
             * }
             */
            /* e.g. /user/login/[email protected]/password=12345 */
            try
            {
                BeginLogin();
                ModelService <User> srvUser = await ServiceConnector.GetServiceData <ModelService <User> >("/user/login/email=" + user.Email + "/password="******" " + ex.Message;
                EndLogin();
            }
            MessageLabel.Text = Properties.LangResource.wrongcredentials;
        }
Exemple #3
0
        public async static Task LoginSynch()
        {
            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    User         loginUser    = StorageManager.GetConnectionInfo().LoginUser;
                    UserSettings usersettings = StorageManager.GetConnectionInfo().UserSettings;
                    string       gencall      = "/accesstoken=" + loginUser.AccessToken + "/updatedate=" + usersettings.LastSyncDate.ToString("yyyyMMddTHHmmss");
                    string       usercall     = gencall + "/iduser="******"/plan/getall" + usercall);

                    servPlan.SaveAllToDBWithServerID("IDPlan");
                    ModelService <Weight> servWeight = await ServiceConnector.GetServiceData <ModelService <Weight> >("/weight/getall" + usercall);

                    servWeight.SaveAllToDBWithServerID("IDWeight");
                }
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }
Exemple #4
0
        public async static Task FullServiceLoadAndStore(User user, UserSettings usersettings)
        {
            try
            {
                string gencall  = "/accesstoken=" + user.AccessToken + "/updatedate=" + usersettings.LastSyncDate.ToString("yyyyMMddTHHmmss");
                string usercall = gencall + "/iduser="******"/sync/syncdb" + usercall);

                //general calls
                if (servsync.data[0].Unit == 1)
                {
                    ModelService <Unit> servUnit = await ServiceConnector.GetServiceData <ModelService <Unit> >("/unit/getall" + gencall);

                    servUnit.SaveAllToDB();
                }
                if (servsync.data[0].Meal == 1)
                {
                    ModelService <Meal> servMeal = await ServiceConnector.GetServiceData <ModelService <Meal> >("/meal/getall" + usercall);

                    servMeal.SaveAllToDBWithServerID("IDMeal");
                }
                if (servsync.data[0].MealUnit == 1)
                {
                    ModelService <MealUnit> servMealUnit = await ServiceConnector.GetServiceData <ModelService <MealUnit> >("/mealunit/getall" + usercall);

                    servMealUnit.SaveAllToDBWithServerID("IDMealUnit");
                }
                if (servsync.data[0].Package == 1)
                {
                    ModelService <Package> servPackage = await ServiceConnector.GetServiceData <ModelService <Package> >("/package/getall" + gencall);

                    servPackage.SaveAllToDB();
                }
                if (servsync.data[0].Settings == 1)
                {
                    ModelService <Settings> servSettings = await ServiceConnector.GetServiceData <ModelService <Settings> >("/settings/getall" + gencall);

                    Settings settings = StorageManager.GetConnectionInfo().Settings;
                    settings.RemindWeight = servSettings.data[0].RemindWeight;
                    settings.TrialPeriod  = servSettings.data[0].TrialPeriod;
                    settings.UpdateDate   = servSettings.data[0].UpdateDate;
                    StorageManager.UpdateData <Settings>(settings);
                }
                //User calls
                if (servsync.data[0].Alert == 1)
                {
                    ModelService <Alert> servAlert = await ServiceConnector.GetServiceData <ModelService <Alert> >("/alert/getall" + usercall);

                    servAlert.SaveAllToDBWithServerID("IDAlert");
                    IEnumerable <Alert> alts = StorageManager.GetConnection().Query <Alert>("SELECT * FROM Alert WHERE IDUser="******"/exercise/getall" + usercall);

                    servExercise.SaveAllToDBWithServerID("IDExercise");
                }
                if (servsync.data[0].Plan == 1)
                {
                    ModelService <Plan> servPlan = await ServiceConnector.GetServiceData <ModelService <Plan> >("/plan/getall" + usercall);

                    servPlan.SaveAllToDBWithServerID("IDPlan");
                }
                if (servsync.data[0].Subscription == 1)
                {
                    ModelService <Subscription> servSubscription = await ServiceConnector.GetServiceData <ModelService <Subscription> >("/subscription/getall" + usercall);

                    servSubscription.SaveAllToDBWithServerID("IDSubscription");
                }
                if (servsync.data[0].UserMeal == 1)
                {
                    ModelService <UserMeal> servUserMeal = await ServiceConnector.GetServiceData <ModelService <UserMeal> >("/usermeal/getall" + usercall);

                    servUserMeal.SaveAllToDBWithServerID("IDUserMeal");
                }
                if (servsync.data[0].Weight == 1)
                {
                    ModelService <Weight> servWeight = await ServiceConnector.GetServiceData <ModelService <Weight> >("/weight/getall" + usercall);

                    servWeight.SaveAllToDBWithServerID("IDWeight");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private async void OnLoginToFacebook(LoginPageFacebook sender, string json)
        {
            if (json.Equals("error"))
            {
            }
            else
            {
                FacebookObj facebookobj = JsonConvert.DeserializeObject <FacebookObj>(json);
                //TODO DO LOGIN STAFF

                /*
                 * LoginPage login = new LoginPage();
                 * User user = new User();
                 * user.Email = facebookobj.email;
                 * login.AreCredentialsCorrect();
                 */
                try
                {
                    ModelService <User> srvUser = await ServiceConnector.GetServiceData <ModelService <User> >("/user/facebookLogin/email=" + facebookobj.email
                                                                                                               + "/firstname=" + facebookobj.first_name + "/lastname=" + facebookobj.last_name + "/facebookid=" + facebookobj.ID);

                    if (srvUser.success)
                    {
                        User user = new User();
                        user.IDUser    = srvUser.ID;
                        user.Email     = facebookobj.email;
                        user.FirstName = facebookobj.first_name;
                        user.LastName  = facebookobj.last_name;
                        StorageManager.SaveData(user);

                        SQLiteConnection conn  = StorageManager.GetConnection();;
                        List <Weight>    wghts = conn.Query <Weight>("SELECT IDWeight FROM Weight WHERE Deleted=0 AND IDUser="******"SELECT IDPlan FROM Plan WHERE Deleted=0 AND IDUser="******"OK");
                    }
                }
                catch (Exception ex)
                {
                    //MessageLabel.Text = "Error " + ex.Message;
                }
            }
        }