예제 #1
0
        /// <summary>
        /// Handles splitting the data for GetGame method of Friends
        /// </summary>
        public Game(string listingData)
        {
            Name      = listingData.Split('>')[2].Split('<')[0];
            StoreLink = listingData.Split('=')[3].Replace("\"", "").Split('?')[0];
            AppId     = int.Parse(listingData.Split('=')[1].Replace("\"", "").Split(' ')[0]);
            ImageLink = listingData.Split('>')[4].Replace("\"", "").Split('=')[1];
            if (ImageLink.Contains("?"))
            {
                ImageLink = ImageLink.Split('?')[0];
            }
            string priceCandidate = listingData.Split('>')[7].Split('<')[0];

            if (priceCandidate == null || priceCandidate.Length < 2)
            {
                Price    = null;
                SaleType = Friends.SaleType.NotAvailable;
            }
            else if (priceCandidate.IndexOf("free", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                Price    = null;
                SaleType = Friends.SaleType.FreeToPlay;
            }
            else
            {
                Price    = double.Parse(priceCandidate.Substring(1), System.Globalization.CultureInfo.InvariantCulture);
                SaleType = Friends.SaleType.CostsMoney;
            }
        }
예제 #2
0
        public async Task Register()
        {
            if (string.IsNullOrWhiteSpace(Mail) || !Mail.Contains("@") || !Mail.Contains(".") || !Mail.Contains("com"))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please enter a valid mail address!", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(FirstName) || FirstName.Length < 4)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "The 'fist name' field requires 4 letters", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(LastName) || LastName.Length < 4)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "The 'last name' field requires 4 letters", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(Address) || Address.Length < 5)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "The 'address' field requires 5 letters", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(ImageLink) || !ImageLink.Contains(".jpg"))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please enter an image link with the '.jpg' extension", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(PhoneNumber) || PhoneNumber.Length < 9)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Please enter a valid phone number", "OK");

                return;
            }

            if (!string.IsNullOrWhiteSpace(PhoneNumber))
            {
                string pattern = @"\(?\d{3}\)?-? ?/*\d{3}-? *-?\d{3}";
                Regex  reg     = new Regex(pattern);
                if (!reg.IsMatch(PhoneNumber))
                {
                    await Application.Current.MainPage.DisplayAlert("Error", "Phone number: xxx / xxx - xxx", "OK");

                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(Username) || Username.Length < 4 || Username.Length > 50)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Username length: 4-50", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(Password) || Password.Length < 4 || Password.Length > 50)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Password length: 4-50", "OK");

                return;
            }

            if (!string.IsNullOrWhiteSpace(Password) && Password.Contains(" "))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Password can't contain spaces", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(ConfirmPassword) || ConfirmPassword.Length < 4 || ConfirmPassword.Length > 50)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Confirmation length: 4-50", "OK");

                return;
            }

            if (!string.IsNullOrWhiteSpace(ConfirmPassword) && ConfirmPassword.Contains(" "))
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Confirmation can't contain spaces", "OK");

                return;
            }

            if (Password != ConfirmPassword)
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Passwords don't match!", "OK");

                return;
            }

            Model.Requests.InsertUserRequest request = new Model.Requests.InsertUserRequest()
            {
                Mail            = Mail,
                Address         = Address,
                BirthDate       = BirthDate,
                ConfirmPassword = ConfirmPassword,
                Password        = Password,
                FirstName       = FirstName,
                ImageLink       = ImageLink,
                LastName        = LastName,
                PhoneNumber     = PhoneNumber,
                Username        = Username
            };

            try {
                var User = await _apiService.Insert <Model.User>(request);

                APIService.Username          = Username;
                APIService.Password          = Password;
                APIService.User              = User;
                Application.Current.MainPage = new MainPage();
                await Application.Current.MainPage.DisplayAlert("Welcome", "Enjoy your stay at Watchables!", "OK");
            }
            catch {
                await Application.Current.MainPage.DisplayAlert("Error", "The username is already taken!", "OK");

                return;
            }
        }