aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/UserCreationDialogVM.cs
blob: 08762ac96df443e50b2cc8ea5eff8c5786aea25b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SimpleValidator.Extensions;
using Tango.SharedUI;

namespace Tango.MachineStudio.UsersAndRoles.ViewModels
{
    public class UserCreationDialogVM : DialogViewVM
    {
        private static Random rnd = new Random();

        private String _email;
        [Required(ErrorMessage = "Email is required")]
        [EmailAddress(ErrorMessage = "Please provide a valid email")]
        public String Email
        {
            get { return _email; }
            set { _email = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        private String _password;
        public String Password
        {
            get { return _password; }
            set { _password = value; RaisePropertyChangedAuto(); }
        }

        private String _firstName;
        [Required(ErrorMessage = "First name is required")]
        public String FirstName
        {
            get { return _firstName; }
            set { _firstName = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        private String _lastName;
        [Required(ErrorMessage = "Last name is required")]
        public String LastName
        {
            get { return _lastName; }
            set { _lastName = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }

        protected override void Accept()
        {
            if (Validate())
            {
                base.Accept();
            }
        }

        public override void OnShow()
        {
            base.OnShow();
            Password = GetRandomPassword(4);
        }

        private String GetRandomPassword(int count)
        {
            String pass = String.Empty;

            for (int i = 0; i < count; i++)
            {
                pass += rnd.Next(0, 9).ToString();
            }

            return pass;
        }
    }
}