public void Create(User user)
        {
            var entity = new User();

            entity.userName = user.userName;
            entity.userFirstName = user.userFirstName;
            entity.userName = user.userName;
            entity.email = user.email;
            entity.password = user.password;
            entity.DateOfBirth = user.DateOfBirth;
            entity.adress = user.adress;
            entity.famSituation = user.famSituation;
            entity.gsmNum = user.gsmNum;
            entity.phoneNum = user.phoneNum;
            entity.nationality = user.nationality;
            entity.country = user.country;
            entity.city = user.city;
            entity.codePoste = user.codePoste;
            entity.DateOfInscri = user.DateOfInscri;

            entities.Users.Add(entity);
            entities.SaveChanges();

            user.userID = entity.userID;
        }
        public void Destroy(User user)
        {
            var entity = new User();

            entity.userID = user.userID;

            entities.Users.Attach(entity);

            entities.Users.Remove(entity);

            /*var orderDetails = entities.Order_Details.Where(pd => pd.ProductID == entity.ProductID);

            foreach (var orderDetail in orderDetails)
            {
                entities.Order_Details.Remove(orderDetail);
            }
            */
            entities.SaveChanges();
        }
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                context.Users.Add(user);

                Session["LogedUserID"] = user.userID.ToString();
                Session["LogedUserFirstname"] = user.userFirstName.ToString();
                Session["LogedUserName"] = user.userName.ToString();

                FormsAuthentication.SetAuthCookie(user.email, false);
                context.SaveChanges();
                Session["LoggedUserRole"] = Roles.GetRolesForUser(user.email);

                Roles.AddUserToRole(user.email, "User");
                return RedirectToAction("Index", "Home");
            }

            return View(user);
        }
        public void Update(User user)
        {
            var entity = new User();

            entity.userName = user.userName;
            entity.userFirstName = user.userFirstName;
            entity.email = user.email;
            entity.password = user.password;
            entity.DateOfBirth = user.DateOfBirth;
            entity.adress = user.adress;
            entity.famSituation = user.famSituation;
            entity.gsmNum = user.gsmNum;
            entity.phoneNum = user.phoneNum;
            entity.nationality = user.nationality;
            entity.country = user.country;
            entity.city = user.city;
            entity.codePoste = user.codePoste;
            entity.DateOfInscri = user.DateOfInscri;
            entities.Users.Attach(entity);
            entities.Entry(entity).State = EntityState.Modified;
            entities.SaveChanges();
        }
        public ActionResult Login(User user)
        {
            if (ModelState.IsValid)
            {
                using (RecruteContext contex = new RecruteContext())
                {
                    var v = contex.Users.Where(a => a.email.Equals(user.email) && a.password.Equals(user.password)).FirstOrDefault();
                    if (v != null)
                    {
                        Session["LogedUserID"] = v.userID.ToString();
                        Session["LogedUserFirstname"] = v.userFirstName.ToString();
                        Session["LogedUserName"] = v.userName.ToString();
                        Session["LoggedUserRole"] = Roles.GetRolesForUser(v.email);
                        FormsAuthentication.SetAuthCookie(v.email, false);
                        return RedirectToAction("Details", "User", new { id = v.userID });
                    }
                }
            }
                else
                {
                    ModelState.AddModelError("Erreur", "Email ou Mot de passe invalides!");
                }

            return View();
        }
        public ActionResult Edit(int id, User user)
        {
            User _user = context.Users.Find(id);

            if (ModelState.IsValid)
            {
                _user.userName = user.userName;
                _user.userFirstName = user.userFirstName;
                _user.email = user.email;
                _user.password = user.password;
                _user.DateOfBirth = user.DateOfBirth;
                _user.nationality = user.nationality;
                _user.placeOfBirth = user.placeOfBirth;
                _user.famSituation = user.famSituation;
                _user.phoneNum = user.phoneNum;
                _user.gsmNum = user.gsmNum;
                _user.adress = user.adress;
                _user.city = user.city;
                _user.country = user.country;
                _user.codePoste = user.codePoste;

                context.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(user);
        }