Révision 18f910c6 GES_PAC/ViewModel/CreatePlaceViewModel.cs

Voir les différences:

GES_PAC/ViewModel/CreatePlaceViewModel.cs
5 5
{
6 6
    public class CreatePlaceViewModel : BaseViewModel
7 7
    {
8
        #region Attributs
8 9
        private string _nom;
10
        private string _client;
11
        private string _espece;
12
        private bool _isFormValid;
13
        #endregion
14

  
15
        #region Commandes
16
        public ICommand CreatePlaceCommand { get; }
17
        #endregion
18

  
19
        #region Propriétés
9 20
        public string Nom
10 21
        {
11 22
            get => _nom;
......
16 27
                ValidateForm();
17 28
            }
18 29
        }
19
        private string _client;
30
        
20 31
        public string Client
21 32
        {
22 33
            get => _client;
......
27 38
                ValidateForm();
28 39
            }
29 40
        }
30
        private bool _isFormValid;
41
        public string Espece
42
        {
43
            get => _espece;
44
            set
45
            {
46
                _espece = value;
47
                OnPropertyChanged();
48
                ValidateForm();
49
            }
50
        }
51

  
31 52
        public bool IsFormValid
32 53
        {
33 54
            get => _isFormValid;
......
40 61

  
41 62
        public bool NomError { get; private set; } = true;
42 63
        public bool ClientError { get; private set; } = true;
64
        public bool EspeceError { get; private set; } = true;
65
        #endregion
43 66

  
44
        public ICommand ReturnCommand { get; }
45
        public ICommand CreatePlaceCommand { get; }
46

  
67
        #region Constructeur
47 68
        public CreatePlaceViewModel()
48 69
        {
49
            ReturnCommand = new Command(async () => await Return());
50 70
            CreatePlaceCommand = new Command(async () => await CreatePlace());
51 71
        }
72
        #endregion
52 73

  
74
        #region Méthodes
53 75
        private void ValidateForm()
54 76
        {
55 77
            NomError = string.IsNullOrWhiteSpace(Nom) || Nom.Length < 3;
56 78
            ClientError = string.IsNullOrWhiteSpace(Client) || Client.Length < 3;
79
            EspeceError = string.IsNullOrWhiteSpace(Espece) || Espece.Length < 3;
57 80

  
58 81
            OnPropertyChanged(nameof(NomError));
59 82
            OnPropertyChanged(nameof(ClientError));
83
            OnPropertyChanged(nameof(EspeceError));
60 84

  
61
            IsFormValid = !NomError && !ClientError;
85
            IsFormValid = !NomError && !ClientError && !EspeceError;
62 86
            (CreatePlaceCommand as Command)?.ChangeCanExecute();
63 87
        }
64
        private async Task Return()
65
        {
66
            await Shell.Current.GoToAsync("..");
67
        }
68 88
        private async Task CreatePlace()
69 89
        {
70
            var newPlace = new Lieu(Nom, Client);
90
            var newPlace = new Lieu(Nom, Client, Espece);
71 91
            PlaceViewModel.Instance.Places.Add(newPlace);
72
            await Shell.Current.GoToAsync("..");
92
            await Shell.Current.GoToAsync("//Main");
73 93
        }
74
               
94
        #endregion
75 95
    }
76 96
}

Formats disponibles : Unified diff