public ActionResult Edit(int ID) { var roleList = _context.Roles.ToList(); var langueList = _context.Languages.ToList(); var user = _context.Users.Find(ID); var userModel = new UserModel() { ID = user.ID, Name = user.Name, LanguagesID = user.LanguagesID, RoleID = user.RoleID, Email = user.Email, PhoneNumber = user.PhoneNumber, Pwd = Utilitaire.Sha256(user.Pwd), Active = user.Active, CreateDate = user.CreateDate }; var data = new UserViewModel() { Languages = langueList, Roles = roleList, UserModel = userModel }; return(View(data)); }
public ActionResult Create(UserModel userModel) { if (ModelState.IsValid) { var user = new User() { Name = userModel.Name, LanguagesID = userModel.LanguagesID, RoleID = userModel.RoleID, Email = userModel.Email, PhoneNumber = userModel.PhoneNumber, Pwd = Utilitaire.Sha256(userModel.Pwd), Active = userModel.Active, CreateDate = DateTime.Now }; _context.Users.Add(user); _context.SaveChanges(); return(RedirectToAction("List", "User")); } return(View("New", userModel)); }
private LoginProfileSession CheckUser(string email, string pwd) { var mdp = Utilitaire.Sha256(pwd); var users = _context.Users .Include(m => m.Role) .Include(m => m.Languages) .Where(m => m.Email.Equals(email)) .Where(m => m.Pwd.Equals(mdp)) .Where(m => m.Active == true) .ToList(); if (users.Count() > 0) { var profile = new LoginProfileSession() { ID = users[0].ID, Name = users[0].Name, Role = users[0].Role.RoleName, Email = users[0].Email }; return(profile); } return(null); }