public ActionResult Edit(user user) { try { ViewBag.Message = "Editar User"; IList <role> ilm = r.GetAll().ToList(); ViewBag.roleref = ilm; user.Login = user.Login.Trim(); var senhaCriptografada = Criptografic.Codifica(user.Password); user.Password = senhaCriptografada; var numUser = ur.GetAll().Where(x => x.Login == user.Login && x.Id != user.Id).Count(); if (numUser > 0) { ViewBag.error = "Já existe este login no sistema"; return(View("Edit", user)); } else { ur.Update(user); return(RedirectToAction("Index")); } } catch (Exception) { return(View(user)); } }
public ActionResult Create(user user) { try { var senhaCriptografada = Criptografic.Codifica(user.Password); user.Password = senhaCriptografada; user.Login = user.Login.Trim(); var numUser = ur.GetAll().Where(x => x.Login == user.Login).Count(); if (numUser > 0) { string error = "Já existe este login no sistema"; return(RedirectToAction("Create", new { erro = error })); } else { ur.Save(user); return(RedirectToAction("Index")); } } catch { return(View()); } }