Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.53 KB | None | 0 0
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using GalaSoft.MvvmLight.Views;
  4. using Model;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Input;
  12.  
  13. namespace ClickNTrip.ViewModel
  14. {
  15.     public class VisitorCreateProfileViewModel : ViewModelBase
  16.     {
  17.         private User _newUser;
  18.         public User NewUser
  19.         {
  20.             get
  21.             {
  22.                 return _newUser;
  23.             }
  24.             set
  25.             {
  26.                 if (value != _newUser)
  27.                 {
  28.                     _newUser = value;
  29.                     OnNotifyPropertyChanged("NewUser");
  30.                 }
  31.             }
  32.         }
  33.         private String _retypedPassword;
  34.         public String RetypedPassword
  35.         {
  36.             get
  37.             {
  38.                 return _retypedPassword;
  39.             }
  40.             set
  41.             {
  42.                 if (value != _retypedPassword)
  43.                 {
  44.                     _retypedPassword = value;
  45.                     OnNotifyPropertyChanged("RetypedPassword");
  46.                 }
  47.             }
  48.         }
  49.         private DateTime _today = DateTime.Now;
  50.         private DateTime _birthdate;
  51.         public DateTime Birthdate
  52.         {
  53.             get
  54.             {
  55.                 return _birthdate;
  56.             }
  57.             set
  58.             {
  59.                 if (_birthdate == null)
  60.                 {
  61.                     _birthdate = value;
  62.                     OnNotifyPropertyChanged("Birthdate");
  63.                 }
  64.             }
  65.         }
  66.         public event PropertyChangedEventHandler PropertyChanged;
  67.  
  68.         public void OnNotifyPropertyChanged(string property)
  69.         {
  70.             if (PropertyChanged != null)
  71.             {
  72.                 PropertyChanged(this, new PropertyChangedEventArgs(property));
  73.             }
  74.         }
  75.         private INavigationService _navigationService;
  76.         public VisitorCreateProfileViewModel(INavigationService navigationService)
  77.         {
  78.             NewUser = new User
  79.             {
  80.                 Email = "",
  81.                 Password = "",
  82.                 Name = "",
  83.                 FirstName = "",
  84.             };
  85.             Birthdate = _today;
  86.             _navigationService = navigationService;
  87.         }
  88.  
  89.         private ICommand _goBackToHomeCommand;
  90.         public ICommand GoBackToHomeCommand
  91.         {
  92.             get
  93.             {
  94.                 if (_goBackToHomeCommand == null)
  95.                 {
  96.                     _goBackToHomeCommand = new RelayCommand(() => GoBackToHome());
  97.                 }
  98.  
  99.                 return _goBackToHomeCommand;
  100.             }
  101.         }
  102.         private void GoBackToHome()
  103.         {
  104.             _navigationService.NavigateTo("HomeVisitor");
  105.         }
  106.  
  107.         private ICommand _goNextCommand;
  108.         public ICommand GoNextCommand
  109.         {
  110.             get
  111.             {
  112.                 if (_goNextCommand == null)
  113.                 {
  114.                     _goNextCommand = new RelayCommand(() => GoNext());
  115.                 }
  116.  
  117.                 return _goNextCommand;
  118.             }
  119.         }
  120.         private void GoNext()
  121.         {
  122.             if(NotEmptyEmail(NewUser) && NotEmptyFirstName(NewUser) && NotEmptyName(NewUser) && SamePassword(NewUser, RetypedPassword) && CorrectBirthDate(Birthdate))
  123.             {
  124.                 _navigationService.NavigateTo("CreateProfileOptionalVisitor", NewUser);
  125.             }
  126.         }
  127.  
  128.         private bool SamePassword(User NewUser, String RetypedPassword)
  129.         {
  130.             if(NewUser.Password.Equals(RetypedPassword) && !NewUser.Password.Equals(""))
  131.             {
  132.                 return true;
  133.             }
  134.             else
  135.             {
  136.                 //Different passwords or empty fields
  137.                 return false;
  138.             }
  139.         }
  140.         private bool NotEmptyName(User NewUser)
  141.         {
  142.             if (!NewUser.Name.Equals("")) return true;
  143.             else return false;
  144.         }
  145.         private bool NotEmptyFirstName(User NewUser)
  146.         {
  147.             if (!NewUser.FirstName.Equals("")) return true;
  148.             else return false;
  149.         }
  150.         private bool NotEmptyEmail(User NewUser)
  151.         {
  152.             if (!NewUser.Email.Equals("")) return true;
  153.             else return false;
  154.         }
  155.         private bool CorrectBirthDate(DateTime Birthdate)
  156.         {
  157.             if (Birthdate < _today) return true;
  158.             else return false;
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement