public ActionResult <Model.User> Update(int userId, Model.Requests.InsertUserRequest request)
 {
     return(_service.Update(userId, request));
 }
Exemple #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;
            }
        }
 public ActionResult <Model.User> Insert(Model.Requests.InsertUserRequest request)
 {
     return(_service.Insert(request));
 }