Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Views;
- using Model;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- namespace ClickNTrip.ViewModel
- {
- public class VisitorCreateProfileViewModel : ViewModelBase
- {
- private User _newUser;
- public User NewUser
- {
- get
- {
- return _newUser;
- }
- set
- {
- if (value != _newUser)
- {
- _newUser = value;
- OnNotifyPropertyChanged("NewUser");
- }
- }
- }
- private String _retypedPassword;
- public String RetypedPassword
- {
- get
- {
- return _retypedPassword;
- }
- set
- {
- if (value != _retypedPassword)
- {
- _retypedPassword = value;
- OnNotifyPropertyChanged("RetypedPassword");
- }
- }
- }
- private DateTime _today = DateTime.Now;
- private DateTime _birthdate;
- public DateTime Birthdate
- {
- get
- {
- return _birthdate;
- }
- set
- {
- if (_birthdate == null)
- {
- _birthdate = value;
- OnNotifyPropertyChanged("Birthdate");
- }
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- public void OnNotifyPropertyChanged(string property)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(property));
- }
- }
- private INavigationService _navigationService;
- public VisitorCreateProfileViewModel(INavigationService navigationService)
- {
- NewUser = new User
- {
- Email = "",
- Password = "",
- Name = "",
- FirstName = "",
- };
- Birthdate = _today;
- _navigationService = navigationService;
- }
- private ICommand _goBackToHomeCommand;
- public ICommand GoBackToHomeCommand
- {
- get
- {
- if (_goBackToHomeCommand == null)
- {
- _goBackToHomeCommand = new RelayCommand(() => GoBackToHome());
- }
- return _goBackToHomeCommand;
- }
- }
- private void GoBackToHome()
- {
- _navigationService.NavigateTo("HomeVisitor");
- }
- private ICommand _goNextCommand;
- public ICommand GoNextCommand
- {
- get
- {
- if (_goNextCommand == null)
- {
- _goNextCommand = new RelayCommand(() => GoNext());
- }
- return _goNextCommand;
- }
- }
- private void GoNext()
- {
- if(NotEmptyEmail(NewUser) && NotEmptyFirstName(NewUser) && NotEmptyName(NewUser) && SamePassword(NewUser, RetypedPassword) && CorrectBirthDate(Birthdate))
- {
- _navigationService.NavigateTo("CreateProfileOptionalVisitor", NewUser);
- }
- }
- private bool SamePassword(User NewUser, String RetypedPassword)
- {
- if(NewUser.Password.Equals(RetypedPassword) && !NewUser.Password.Equals(""))
- {
- return true;
- }
- else
- {
- //Different passwords or empty fields
- return false;
- }
- }
- private bool NotEmptyName(User NewUser)
- {
- if (!NewUser.Name.Equals("")) return true;
- else return false;
- }
- private bool NotEmptyFirstName(User NewUser)
- {
- if (!NewUser.FirstName.Equals("")) return true;
- else return false;
- }
- private bool NotEmptyEmail(User NewUser)
- {
- if (!NewUser.Email.Equals("")) return true;
- else return false;
- }
- private bool CorrectBirthDate(DateTime Birthdate)
- {
- if (Birthdate < _today) return true;
- else return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement