public void CreateUserWithParametersRole()
 {
     User u = null;
     Assert.IsNull(u);
     DateTime d = DateTime.Now;
     u = new User("Kent", "Clark", "*****@*****.**", "12345", PasswordHashing.HashPassword("12345"), d, "Ice Fortress", Roles.admin);
     Assert.IsNotNull(u);
     Assert.IsNotNull(u.UserID);
     Assert.IsTrue(u.Adresse == "Ice Fortress");
     Assert.IsTrue(u.Email == "*****@*****.**");
     Assert.IsTrue(u.Nom == "Kent");
     Assert.IsTrue(u.NoPolice == "12345");
     Assert.IsTrue(PasswordHashing.VerifyHashedPassword(u.Password, "12345"));
     Assert.IsTrue(u.Prenom == "Clark");
     Assert.IsTrue(u.Role == Roles.admin);
     Assert.IsTrue(u.DateNaissance == DateTime.Parse(d.ToShortDateString()));
 }
 public void CreateUserWithParametersTextDate()
 {
     User u = null;
     Assert.IsNull(u);
     DateTime d = DateTime.Now;
     u = new User("Allen", "Barry", "*****@*****.**", "12345", PasswordHashing.HashPassword("12345"), d.ToShortDateString(), "Her.. wait no over there", Roles.reparateur);
     Assert.IsNotNull(u);
     Assert.IsNotNull(u.UserID);
     Assert.IsTrue(u.Adresse == "Her.. wait no over there");
     Assert.IsTrue(u.Email == "*****@*****.**");
     Assert.IsTrue(u.Nom == "Allen");
     Assert.IsTrue(u.NoPolice == "12345");
     Assert.IsTrue(PasswordHashing.VerifyHashedPassword(u.Password, "12345"));
     Assert.IsTrue(u.Prenom == "Barry");
     Assert.IsTrue(u.Role == Roles.reparateur);
     Assert.IsTrue(u.DateNaissance == DateTime.Parse(d.ToShortDateString()));
 }
 public void CreateUser()
 {
     User u = null;
     Assert.IsNull(u);
     u = new User();
     Assert.IsNotNull(u);
     Assert.IsNotNull(u.UserID);
     Assert.IsNull(u.Adresse);
     Assert.IsNull(u.Email);
     Assert.IsNull(u.Nom);
     Assert.IsNull(u.NoPolice);
     Assert.IsNull(u.Password);
     Assert.IsNull(u.Prenom);
     Assert.IsTrue(u.Role == Roles.client);
     Assert.IsNotNull(u.DateNaissance);
 }
 public void CreateUserWithParameters()
 {
     User u = null;
     Assert.IsNull(u);
     DateTime d = DateTime.Now;
     u = new User("Wayne", "Bruce", "*****@*****.**", "12345", PasswordHashing.HashPassword("12345"), d, "Wayne Manor");
     Assert.IsNotNull(u);
     Assert.IsNotNull(u.UserID);
     Assert.IsTrue(u.Adresse == "Wayne Manor");
     Assert.IsTrue(u.Email == "*****@*****.**");
     Assert.IsTrue(u.Nom == "Wayne");
     Assert.IsTrue(u.NoPolice == "12345");
     Assert.IsTrue(PasswordHashing.VerifyHashedPassword(u.Password, "12345"));
     Assert.IsTrue(u.Prenom == "Bruce");
     Assert.IsTrue(u.Role == Roles.client);
     Assert.IsTrue(u.DateNaissance == DateTime.Parse(d.ToShortDateString()));
 }
 public CustomPrincipal(User user)
 {
     User = user;
     Identity = new GenericIdentity(User.Email);
 }
        public ActionResult Register(User user)
        {

            UserModel userMod = new UserModel();
            if (userMod.Find(user.Email) != null)
            {
                ViewBag.UsernameError = "L'adresse courriel est déjà utilisée doit être unique";
            }

            if (!userMod.Insert(user))
            {
                return View("Register");
            }
            return RedirectToAction("List");
        }
 public bool Edit(User user)
 {
     try
     {
         listUser[listUser.FindIndex(u => u.Email == user.Email)] = user;
         CooperatorsContext.Entry(CooperatorsContext.Clients.First(u => u.Email == user.Email)).CurrentValues.SetValues(user);
         CooperatorsContext.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 public bool Insert(User user)
 {
     try
     {
         if (user.Password != string.Empty && user.Password != null)
         {
             user.Password = PasswordHashing.HashPassword(user.Password);
         }
         listUser.Add(user);
         CooperatorsContext.Add(user);
         CooperatorsContext.SaveChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 public void Add(User user)
 {
     Clients.Add(user);
 }