コード例 #1
0
        public LoginViewModel(IMvxNavigationService navigationService, IAuthService authService, IUserDialogs userDialogs, IValidator validator, IBottomNavigationViewModelService bottomNavigationViewModelService, ITopNavigationViewModelService topNavigationViewModelService)
        {
            _navigationService                = navigationService;
            _topNavigationViewModelService    = topNavigationViewModelService;
            _bottomNavigationViewModelService = bottomNavigationViewModelService;

            _authService = authService;
            _userDialogs = userDialogs;

            _validationHelper = new ValidationHelper(validator, this, Errors.Value, (propertyName) => { FocusName.Value = propertyName; });

            ValidateEmailCommand    = new MvxCommand(() => _validationHelper.Validate(() => Email));
            ValidatePasswordCommand = new MvxCommand(() => _validationHelper.Validate(() => Password));

            InitValidationCommand = new MvxCommand(() => {
                _validationHelper.ResetValidation();
            });

            LogInCommand = new MvxCommand(() =>
            {
                if (!IsTaskExecutedValueConverter.Convert(LogInTask.Value))
                {
                    LogInTask.Value = NotifyTaskCompletion.Create(AttemptLogInAsync);
                }
            });

            ShowRegistrationViewModelCommand = new MvxAsyncCommand(async() =>
            {
                await _navigationService.Navigate <RegistrationViewModel>();
            });
        }
コード例 #2
0
        public ChangeAlbumViewModel(IMvxNavigationService navigationService, IUserDialogs userDialogs, IValidator validator, ISongService songService, IGenreService genreService, IArtistService artistService, IAlbumService albumService, IBottomNavigationViewModelService bottomNavigationViewModelService, ITopNavigationViewModelService topNavigationViewModelService)
        {
            _navigationService                = navigationService;
            _topNavigationViewModelService    = topNavigationViewModelService;
            _bottomNavigationViewModelService = bottomNavigationViewModelService;

            _userDialogs = userDialogs;

            _validationHelper = new ValidationHelper(validator, this, Errors.Value, (propertyName) => { FocusName.Value = propertyName; });

            _songService   = songService;
            _genreService  = genreService;
            _artistService = artistService;
            _albumService  = albumService;

            ValidateNameCommand = new MvxCommand(() => _validationHelper.Validate(() => Name));

            ValidateGenresCommand = new MvxCommand(() => _validationHelper.Validate(() => Genres));

            ValidateArtistsCommand = new MvxCommand(() => _validationHelper.Validate(() => Artists));

            ValidateSongsCommand = new MvxCommand(() => _validationHelper.Validate(() => Songs));

            InitValidationCommand = new MvxCommand(() => {
                _validationHelper.ResetValidation();
            });

            ChangeCommand = new MvxCommand(() =>
            {
                if (!IsTaskExecutedValueConverter.Convert(ChangeTask.Value))
                {
                    ChangeTask.Value = NotifyTaskCompletion.Create(AttemptChangeAsync);
                }
            });

            _genresTokenParentObject = new TokenParentHelper(new MvxCommand <TokenViewModel>((_) =>
            {
                Genres.Value?.Remove(_ as TokenViewModel <GenreModel>);
                ValidateGenresCommand.Execute(null);
            }));

            _artistsTokenParentObject = new TokenParentHelper(new MvxCommand <TokenViewModel>((_) =>
            {
                Artists.Value?.Remove(_ as TokenViewModel <ArtistModel>);
                ValidateArtistsCommand.Execute(null);
            }));

            _songsTokenParentObject = new TokenParentHelper(new MvxCommand <TokenViewModel>((_) =>
            {
                Songs.Value?.Remove(_ as TokenViewModel <SongModel>);
                ValidateSongsCommand.Execute(null);
            }));
        }
コード例 #3
0
        public RegistrationViewModel(IMvxNavigationService navigationService, IAuthService authService, IUserDialogs userDialogs, IValidator validator /*, ILocationService locationService*/, MvvmCross.Plugins.Validation.IMvxToastService toastService, IBottomNavigationViewModelService bottomNavigationViewModelService, ITopNavigationViewModelService topNavigationViewModelService)
        {
            _navigationService                = navigationService;
            _topNavigationViewModelService    = topNavigationViewModelService;
            _bottomNavigationViewModelService = bottomNavigationViewModelService;

            _authService  = authService;
            _userDialogs  = userDialogs;
            _toastService = toastService;

            _validationHelper = new ValidationHelper(validator, this, Errors.Value, (propertyName) => { FocusName.Value = propertyName; });

            //_locationService = locationService;

            ValidateEmailCommand     = new MvxCommand(() => _validationHelper.Validate(() => Email));
            ValidateFirstNameCommand = new MvxCommand(() => _validationHelper.Validate(() => FirstName));
            ValidateLastNameCommand  = new MvxCommand(() => _validationHelper.Validate(() => LastName));
            ValidatePasswordCommand  = new MvxCommand(() => _validationHelper.Validate(() => Password));
            ValidateBirthDateCommand = new MvxCommand(() => _validationHelper.Validate(() => BirthDate));

            RegisterCommand = new MvxCommand(() =>
            {
                if (!IsTaskExecutedValueConverter.Convert(RegisterTask.Value))
                {
                    RegisterTask.Value = NotifyTaskCompletion.Create(AttemptRegisterAsync);
                }
            });

            ChangeBirthDateCommand = new MvxAsyncCommand(async() => {
                var datePromptResult = await _userDialogs.DatePromptAsync(new DatePromptConfig()
                {
                    MinimumDate = new DateTime(1900, 1, 1), MaximumDate = DateTime.Now, SelectedDate = BirthDate.Value ?? new DateTime?(new DateTime(1990, 1, 1)), OkText = "OK", CancelText = "Cancel"
                });
                if (datePromptResult.Ok)
                {
                    BirthDate.Value = new DateTime?(datePromptResult.SelectedDate);
                }
                else
                {
                    BirthDate.Value = null;
                }
                ValidateBirthDateCommand.Execute(null);
            });

            InitValidationCommand = new MvxCommand(() => {
                _validationHelper.ResetValidation();
            });
        }
コード例 #4
0
        public ChangeArtistViewModel(IMvxNavigationService navigationService, IUserDialogs userDialogs, IValidator validator, IArtistService artistService, IBottomNavigationViewModelService bottomNavigationViewModelService, ITopNavigationViewModelService topNavigationViewModelService)
        {
            _navigationService                = navigationService;
            _topNavigationViewModelService    = topNavigationViewModelService;
            _bottomNavigationViewModelService = bottomNavigationViewModelService;

            _userDialogs = userDialogs;

            _validationHelper = new ValidationHelper(validator, this, Errors.Value, (propertyName) => { FocusName.Value = propertyName; });

            _artistService = artistService;

            ValidateNameCommand = new MvxCommand(() => _validationHelper.Validate(() => Name));

            InitValidationCommand = new MvxCommand(() => {
                _validationHelper.ResetValidation();
            });

            ChangeCommand = new MvxCommand(() =>
            {
                if (!IsTaskExecutedValueConverter.Convert(ChangeTask.Value))
                {
                    ChangeTask.Value = NotifyTaskCompletion.Create(AttemptChangeAsync);
                }
            });
        }
コード例 #5
0
        // Private methods

        private async Task AttemptChangeAsync()
        {
            Name.Value = Name.Value?.Trim();

            if (_validationHelper.Validate())
            {
                _userDialogs.ShowLoading((string.IsNullOrWhiteSpace(Id.Value) ? "Add" : "Update") + " song");

                var serviceResult = new ServiceResult <SongResultModel>();

                if (string.IsNullOrWhiteSpace(Id.Value))
                {
                    serviceResult = await _songService.Add(new SongResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, Artists = Artists.Value.Select(_ => _.Object.Id).ToList(), Genres = Genres.Value.Select(_ => _.Object.Id).ToList()
                    });
                }
                else
                {
                    serviceResult = await _songService.Update(new SongResultModel()
                    {
                        Id = Id.Value, Name = Name.Value, Artists = Artists.Value.Select(_ => _.Object.Id).ToList(), Genres = Genres.Value.Select(_ => _.Object.Id).ToList()
                    });
                }

                if (serviceResult.Success)
                {
                    await _navigationService.Close(this);

                    _userDialogs.HideLoading();
                    await _userDialogs.AlertAsync(new AlertConfig
                    {
                        Title   = "Success!",
                        Message = serviceResult.Error.Description,
                        OkText  = "OK"
                    });
                }
                else
                {
                    _userDialogs.HideLoading();

                    await _userDialogs.AlertAsync(new AlertConfig
                    {
                        Title   = (string.IsNullOrWhiteSpace(Id.Value) ? "Add" : "Update") + " failed",
                        Message = serviceResult.Error.Description,
                        OkText  = "OK"
                    });

                    InitValidationCommand.Execute(null);
                }
            }
        }
コード例 #6
0
        // Private methods

        private async Task AttemptRegisterAsync()
        {
            Email.Value     = Email.Value?.Trim();
            FirstName.Value = FirstName.Value?.Trim();
            LastName.Value  = LastName.Value?.Trim();
            Password.Value  = Password.Value?.Trim();

            if (_validationHelper.Validate())
            {
                _userDialogs.ShowLoading("Registration");

                var user = new ApplicationUserModel()
                {
                    Email = Email.Value, FirstName = FirstName.Value, LastName = LastName.Value, Password = Password.Value, BirthDate = BirthDate.Value
                };

                var serviceResult = await _authService.Register(user);

                if (serviceResult.Success)
                {
                    await _navigationService.Navigate <LoginViewModel, ApplicationUserModel>(new ApplicationUserModel()
                    {
                        Email = Email.Value, Password = Password.Value
                    });

                    _userDialogs.HideLoading();
                }
                else
                {
                    _userDialogs.HideLoading();
                    await _userDialogs.AlertAsync(new AlertConfig
                    {
                        Title   = "Registration failed",
                        Message = serviceResult.Error.Description,
                        OkText  = "OK"
                    });

                    InitValidationCommand.Execute(null);
                }
            }
        }
コード例 #7
0
        // Private methods

        private async Task AttemptLogInAsync()
        {
            Email.Value    = Email.Value?.Trim();
            Password.Value = Password.Value?.Trim();

            if (_validationHelper.Validate())
            {
                _userDialogs.ShowLoading("Login");

                var serviceResult = await _authService.Login(Email.Value, Password.Value);

                if (serviceResult.Success)
                {
                    ClearStack.Execute(null);
                    await _navigationService.Navigate <HomeViewModel>();

                    await _bottomNavigationViewModelService.Show(new BottomNavigationViewModel.PrepareModel()
                    {
                        CheckedItem = Enums.BottomNavigationViewCheckedItemType.Home
                    });

                    _userDialogs.HideLoading();
                }
                else
                {
                    _userDialogs.HideLoading();

                    await _userDialogs.AlertAsync(new AlertConfig
                    {
                        Title   = "Login failed",
                        Message = serviceResult.Error.Description,
                        OkText  = "OK"
                    });

                    InitValidationCommand.Execute(null);
                }
            }
        }