Пример #1
0
        public async void SignUp(User newUser, Action onErrors)
        {
            IUserLoginMenu Vm = _userLoginVm;

            Vm.LoadedUser.Email       = string.Empty;
            Vm.LoadedUser.PhoneNumber = string.Empty;

            var loginConsumer = CommonConsumerFactory.Create(new ConsumerStringIds <TupleJSON>());

            var userConsumer = CommonConsumerFactory.Create(new Consumer <User>());

            bool postOk = await userConsumer.PostAsync(newUser);

            if (postOk)
            {
                //Vm.LoadedUser = newUser;
                NavigationService navigationService = NavigationService.GetService(Contents.UserLoginContent);
                navigationService.Navigate(navigationService.UserLoginProfileMenu, await RetrieveNewUser());
            }
            else if (await CheckNoDuplicates())
            {
                throw new ArgumentException("Post Failed");
            }



            async Task <bool> CheckNoDuplicates()
            {
                TupleJSON mailTuple = await loginConsumer.GetOneAsync(new[] { newUser.Email });

                TupleJSON phoneTuple = await loginConsumer.GetOneAsync(new[] { newUser.PhoneNumber });

                if (mailTuple != null)
                {
                    Vm.LoadedUser.Email = GetUser(mailTuple).Email;
                }
                if (phoneTuple != null)
                {
                    Vm.LoadedUser.PhoneNumber = GetUser(phoneTuple).PhoneNumber;
                }
                onErrors();
                return(string.IsNullOrEmpty(Vm.LoadedUser.Email) && string.IsNullOrEmpty(Vm.LoadedUser.PhoneNumber));
            }

            async Task <User> RetrieveNewUser()
            {
                if (!string.IsNullOrEmpty(newUser.Email))
                {
                    TupleJSON response = await loginConsumer.GetOneAsync(new[] { newUser.Email });

                    return(GetUser(response));
                }
                else
                {
                    TupleJSON response = await loginConsumer.GetOneAsync(new[] { newUser.PhoneNumber });

                    return(GetUser(response));
                }
            }
        }
Пример #2
0
 public UserLoginCompositeHandler(IUserLoginMenu userLoginVm)
 {
     _userLoginVm = userLoginVm;
 }