void SetValidatorValues(string _fullname, string _email, string _phone, string _address, string _gender)
        {
            FullNameValidator = ValidatorRules.EmptyOrNullValueRule(_fullname);
            EmailValidator    = ValidatorRules.EmptyOrNullValueRule(_email);

            if (!EmailValidator.HasError)
            {
                EmailPatternValidator = ValidatorRules.EmailPatternRule(_email);
            }
            PhoneValidator  = ValidatorRules.EmptyOrNullValueRule(_phone);
            AddresValidator = ValidatorRules.EmptyOrNullValueRule(_address);
            GenderValidator = ValidatorRules.EmptyOrNullValueRule(_gender);
        }
Ejemplo n.º 2
0
        void SetValidatorValues()
        {
            UsernameValidator        = ValidatorRules.EmptyOrNullValueRule(Username);
            FullNameValidator        = ValidatorRules.EmptyOrNullValueRule(Fullname);
            PhoneValidator           = ValidatorRules.EmptyOrNullValueRule(Phone);
            AddressValidator         = ValidatorRules.EmptyOrNullValueRule(Address);
            PasswordValidator        = ValidatorRules.EmptyOrNullValueRule(Password);
            ConfirmPasswordValidator = ValidatorRules.EmptyOrNullValueRule(ConfirmPassword);
            EmailValidator           = ValidatorRules.EmptyOrNullValueRule(Email);

            if (!EmailValidator.HasError)
            {
                EmailPatternValidator = ValidatorRules.EmptyOrNullValueRule(Email);
            }
            GenderValidator = ValidatorRules.EmptyOrNullValueRule(GenderSelected);
        }
Ejemplo n.º 3
0
        public RegisterStoreViewModel()
        {
            ValidatorInitializer();
            StoreImage = ImageSource.FromFile("imgPlaceholder.jpg");
            StoreTypes = new List <string>(Enum.GetNames(typeof(StoreType)).ToList());
            #region WorkHourPresenter Initialize
            WorkHourPresenters = new ObservableCollection <WorkHourPresenter>();

            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Monday.ToString()));
            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Tuesday.ToString()));
            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Wednesday.ToString()));
            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Thursday.ToString()));
            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Friday.ToString()));
            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Saturday.ToString()));
            WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Sunday.ToString()));
            #endregion

            PickPhotoCommand = new Command(async() =>
            {
                //Stream stream = await DependencyService.Get<IPickPhotoService>().GetImageStreamAsync();
                //if (stream != null)
                //{
                //    ImgArray = ConvertToByteArray(stream);
                //    StoreImage = ImageSource.FromStream(() => stream);
                //}

                try
                {
                    await CrossMedia.Current.Initialize();

                    files.Clear();

                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        await Shell.Current.DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
                        return;
                    }

                    var mediOptions = new PickMediaOptions()
                    {
                        PhotoSize = PhotoSize.Full,
                    };

                    var selectedImgFile = await CrossMedia.Current.PickPhotoAsync(mediOptions);



                    if (selectedImgFile == null)
                    {
                        return;
                    }



                    ImgArray = ConvertToByteArray(selectedImgFile.GetStream());

                    StoreImage = ImageSource.FromStream(() => selectedImgFile.GetStream());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });

            CompleteRegisterCommand = new Command(async() =>
            {
                TokenExpManger tokenExpManger = new TokenExpManger(App.TokenDto.Exp);
                if (tokenExpManger.IsExpired())
                {
                    await tokenExpManger.CloseSession();
                }
                else
                {
                    List <string> valuesToCheck = new List <string>();

                    valuesToCheck.Add(StoreName);
                    valuesToCheck.Add(LicenseCode);
                    valuesToCheck.Add(StripeSecretKey);
                    valuesToCheck.Add(StripePublicKey);


                    StoreNameValidator        = ValidatorRules.EmptyOrNullValueRule(StoreName);
                    StoreDescriptionValidator = ValidatorRules.EmptyOrNullValueRule(StoreDescription);
                    LicenseCodeValidator      = ValidatorRules.EmptyOrNullValueRule(LicenseCode);

                    SkStripeValidator   = ValidatorRules.EmptyOrNullValueRule(StripeSecretKey);
                    PKeyStripeValidator = ValidatorRules.EmptyOrNullValueRule(StripePublicKey);



                    if (!StoreNameValidator.HasError && !StoreDescriptionValidator.HasError && !LicenseCodeValidator.HasError && !SkStripeValidator.HasError && !PKeyStripeValidator.HasError && GlobalValidator.CheckNullOrEmptyImage(StoreImage))
                    {
                        bool isSKKeyCorrect = StripeSecretKey.StartsWith("sk");
                        bool isPBkeyCorrect = StripePublicKey.StartsWith("pk");
                        if (isSKKeyCorrect || isSKKeyCorrect)
                        {
                            Guid licenseCodeGuid = Guid.Parse(LicenseCode);
                            var licenseResult    = storeLicenseDataStore.StoreLicenseExists(licenseCodeGuid);

                            if (licenseResult)
                            {
                                var licenseIsInUsed = await storeLicenseDataStore.IsLicenseInUsed(LicenseCode);
                                if (!licenseIsInUsed)
                                {
                                    StoreType value;
                                    Enum.TryParse(StoreTypeSelected, out value);

                                    var newStoreRegister = new Store()
                                    {
                                        StoreId                = Guid.NewGuid(),
                                        StoreName              = StoreName,
                                        UserId                 = App.LogUser.UserId,
                                        StoreImage             = ImgArray,
                                        StoreType              = value,
                                        StoreRegisterLicenseId = licenseCodeGuid,
                                        StoreDescription       = StoreDescription,
                                        SKKey = StripeSecretKey,
                                        PBKey = StripePublicKey,
                                    };

                                    List <WorkHour> workHours = new List <WorkHour>();

                                    foreach (var item in WorkHourPresenters)
                                    {
                                        var workHour = new WorkHour()
                                        {
                                            CloseTime  = Convert.ToDateTime(item.Close.ToString()),
                                            Day        = item.Day,
                                            OpenTime   = Convert.ToDateTime(item.Open.ToString()),
                                            WorkHourId = Guid.NewGuid(),
                                            StoreId    = newStoreRegister.StoreId
                                        };

                                        workHours.Add(workHour);
                                    }

                                    newStoreRegister.WorkHours = workHours;

                                    var storeaddedResult = await StoreDataStore.AddItemAsync(newStoreRegister);

                                    if (storeaddedResult)
                                    {
                                        var licenceUpdateResult = await storeLicenseDataStore.UpdateLicenceInCode(licenseCodeGuid);

                                        if (licenceUpdateResult)
                                        {
                                            await Shell.Current.DisplayAlert("Notification", "Store Added...!", "OK");
                                        }
                                    }
                                }
                                else
                                {
                                    await Shell.Current.DisplayAlert("Notification", "This License is in used.", "OK");
                                }
                            }
                            else
                            {
                                await Shell.Current.DisplayAlert("Notification", "License Code Incorrect", "OK");
                            }
                        }
                        else
                        {
                            await Shell.Current.DisplayAlert("Notification", "Srtipe Secret Key or Public Key are set in incorrect entry check again.", "OK");
                        }
                    }
                    else
                    {
                        await Shell.Current.DisplayAlert("Notification", "Some fields are empty", "OK");
                    }
                }
            });
        }
        public RegisterCardViewModel()
        {
            PropertiesInitializer();


            CompleteRegisterCardCommand = new Command(async() =>
            {
                TokenExpManger tokenExpManger = new TokenExpManger(App.TokenDto.Exp);
                if (tokenExpManger.IsExpired())
                {
                    await tokenExpManger.CloseSession();
                }
                else
                {
                    HolderNameValidator = ValidatorRules.EmptyOrNullValueRule(HolderName);
                    CardNumberValidator = ValidatorRules.EmptyOrNullValueRule(CardNumber);
                    YearValidator       = ValidatorRules.EmptyOrNullValueRule(Year);
                    MonthVaidator       = ValidatorRules.EmptyOrNullValueRule(Month);
                    CVCValidator        = ValidatorRules.EmptyOrNullValueRule(CVC);


                    if (!HolderNameValidator.HasError && !CardNumberValidator.HasError && !YearValidator.HasError && !MonthVaidator.HasError && !CVCValidator.HasError)
                    {
                        try
                        {
                            var cardData = new PaymentCard()
                            {
                                CardNumber    = CardNumber,
                                Cvc           = CVC,
                                HolderName    = HolderName,
                                Month         = Month,
                                Year          = Year,
                                PaymentCardId = Guid.NewGuid(),
                                UserId        = App.LogUser.UserId
                            };

                            var cardserviceResult = await stripeServiceDS.InsertStripeCardToStripeUser(cardData, App.LogUser.StripeUserId);

                            if (!cardserviceResult.HasError)
                            {
                                cardData.StripeCardId = cardserviceResult.TokenId;
                                var result            = await CardDataStore.AddItemAsync(cardData);

                                if (result)
                                {
                                    await Shell.Current.DisplayAlert("Notification", "Card succefully added.", "OK");
                                }
                            }
                            else
                            {
                                await Shell.Current.DisplayAlert("Notification", cardserviceResult.ErrorMsg, "OK");
                            }
                        }
                        catch (Exception e)
                        {
                            await Shell.Current.DisplayAlert("Notification", e.Message, "OK");
                        }
                    }
                }
            });
        }