public ActionResult Edit(int?id, UserViewModel userViewModel) { if (!LoginUserSession.IsStateAdmin) { return(RedirectToAction("Login")); } userViewModel.Password = ShaPassword.GetHash(userViewModel.Password); var user = _repository.SelectByID(id.Value); var newUser = Mapper.Map(userViewModel, user); _repository.Update(user); _repository.Save(); return(RedirectToAction("Index")); }
public ActionResult Create(UserViewModel userViewModel) { if (!LoginUserSession.IsStateAdmin) { return(RedirectToAction("Login")); } var user = new User(); userViewModel.Password = ShaPassword.GetHash(userViewModel.Password); var newUser = Mapper.Map(userViewModel, user); _repository.Insert(newUser); _repository.Save(); return(RedirectToAction("Index")); }
public ActionResult Login(UserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } ModelState.Clear(); var hashPasswoed = ShaPassword.GetHash(model.Password); var user = _db.Users.Where(x => x.Name == model.Name && x.Password == hashPasswoed).FirstOrDefault(); if (user != null) { LoginUserSession.SetSessionAndVote(user); return(RedirectToAction("Index", "Home")); } else { ViewBag.Message = "Invalid name or password. Please, try again"; return(View(model)); } }