Esempio n. 1
0
        /// <summary>
        /// This function is used to signup user
        /// </summary>
        /// <param name="u"></param>
        public async void SignupUser(User u)
        {
            IsBusy = true;
            if (u.Email != null && u.Email != "" && u.Password != null && u.Password != "")
            {
                if (Regex.IsMatch(u.Email, AppConstant.EmailPatteren))
                {
                    u.IsSubscribed      = false;
                    u.SubScriptionPrice = 0.0;
                    u.MobileUserId      = "";
                    u.FevoriteId        = "";
                    var           mobileService = new MobileUserService();
                    AppMobileUser mobileUser    = new AppMobileUser();
                    mobileUser.email = u.Email;
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        bool IfEmailPresent = await mobileService.IsMobileUserAlreadyExsit(mobileUser);

                        if (!IfEmailPresent && databaseHelper.AddUser(u))
                        {
                            //LoginUser(u);
                            Settings.IsLogin = true;
                            Settings.Email   = u.Email;
                            var    bytes             = Util.EncryptAes(u.Password);
                            string encryptedPassword = BitConverter.ToString(bytes);
                            Settings.Password = encryptedPassword;

                            Settings.IsSubscriped      = u.IsSubscribed;
                            Settings.SubscriptionPrice = u.SubScriptionPrice;
                            Settings.MobileUserId      = u.MobileUserId;
                            Settings.FevouriteId       = u.FevoriteId;

                            App.Current.MainPage = new Views.Menu.MainPage();
                        }
                        else
                        {
                            await Application.Current.MainPage.DisplayAlert(AppConstant.Sorry, AppConstant.RegistrarionError, AppConstant.Done);
                        }
                    }
                    else
                    {
                        await Application.Current.MainPage.DisplayAlert(AppConstant.NoInternetAlert, AppConstant.NoInternetMessage, AppConstant.Done);
                    }
                    IsBusy = false;
                }
                else
                {
                    IsBusy    = false;
                    ShowError = true;
                    Message   = AppConstant.ValidEmail;
                }
            }
            else
            {
                IsBusy    = false;
                ShowError = true;
                Message   = "Email and Password cannot be empty !";
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Changes the subscription.
        /// </summary>
        /// <returns>The subscription.</returns>
        /// <param name="subscriptionId">Subscription identifier.</param>
        private async Task ChangeSubscription(string subscriptionId, double subscriptionPrice)
        {
            IsBusy = true;
            var           mobileService = new MobileUserService();
            AppMobileUser mobileUser    = new AppMobileUser();

            mobileUser.id                   = Settings.MobileUserId;
            mobileUser.email                = Settings.Email;
            mobileUser.pass_hash            = Settings.Password;
            mobileUser.favorites_id         = Settings.FevouriteId;
            mobileUser.subscription_type_id = subscriptionId;
            mobileUser.created_at           = DateTime.Now.ToString();
            Services.Models.Subscription.Meta meta = new Services.Models.Subscription.Meta();
            meta.author      = AppConstant.AppAuther;
            meta.date_added  = DateTime.Now.ToString();
            meta.last_edited = DateTime.Now.ToString();
            mobileUser.meta  = meta;

            if (!String.IsNullOrEmpty(subscriptionId))
            {
                mobileUser.is_active = "true";
            }
            else
            {
                mobileUser.is_active = "false"; //susbcription has been cancelled
            }
            AppMobileUser user = await mobileService.UpdateMobileUser(mobileUser);

            if (!String.IsNullOrEmpty(subscriptionId))
            {
                Settings.MobileUserId      = user.id;
                Settings.FevouriteId       = user.favorites_id;
                Settings.IsSubscriped      = true;
                Settings.SubscriptionPrice = subscriptionPrice;
                UpdateSubscriptionInLocalDB(true, subscriptionPrice, user.id, user.favorites_id);
            }
            else
            {
                Settings.IsSubscriped      = false;
                Settings.SubscriptionPrice = 0.0;
                UpdateSubscriptionInLocalDB(false, 0.0, user.id, user.favorites_id);
            }
            IsBusy = false;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the new mobile user on the server
        /// </summary>
        /// <param name="subscriptionId">Subscription identifier.</param>
        private async Task CreateMobileUser(string subscriptionId, double subscriptionPrice)
        {
            if (string.IsNullOrEmpty(Settings.FevouriteId)) //indicate the subcription is going to be happened very first time
            {
                IsBusy = true;
                var           mobileService = new MobileUserService();
                AppMobileUser mobileUser    = new AppMobileUser();
                mobileUser.id                   = Guid.NewGuid().ToString();
                mobileUser.email                = Settings.Email;
                mobileUser.pass_hash            = Settings.Password;
                mobileUser.favorites_id         = Guid.NewGuid().ToString();
                mobileUser.is_active            = "true";
                mobileUser.subscription_type_id = subscriptionId;
                mobileUser.created_at           = DateTime.Now.ToString();

                Services.Models.Subscription.Meta meta = new Services.Models.Subscription.Meta();
                meta.author      = AppConstant.AppAuther;
                meta.date_added  = DateTime.Now.ToString();
                meta.last_edited = DateTime.Now.ToString();
                mobileUser.meta  = meta;

                AppMobileUser user = await mobileService.CreateMobileUser(mobileUser);

                Settings.MobileUserId      = user.id;
                Settings.FevouriteId       = user.favorites_id;
                Settings.IsSubscriped      = true;
                Settings.SubscriptionPrice = subscriptionPrice;

                UpdateSubscriptionInLocalDB(true, subscriptionPrice, user.id, user.favorites_id);

                await PostUserFevorite(); //Post users fevourites if available

                IsBusy = false;
            }
            else
            {
                //Only update subscription status. don't create new user
                await ChangeSubscription(subscriptionId, subscriptionPrice);
            }
        }