public ActionResult TestAddUser() { Usuario user = new Usuario(); user.UserName = "******"; user.Senha = "admin"; user.IsAdm = true; usuarioBusiness.Add(user); Usuario user2 = new Usuario(); user2.UserName = "******"; user2.Senha = "sorvetegostoso"; user2.IsAdm = false; usuarioBusiness.Add(user2); return(View()); }
public ActionResult Cadastrar(UsuarioModel model) { var usuario = AutenticacaoProvider.UsuarioAutenticado; if (usuario == null) { return(RedirectToAction("Login", "CommonViews")); } try { if (ModelState.IsValid) { if (_busUsuario.Add(model)) { notificacao = true; return(RedirectToAction("Lista")); } model.Perfis = _busPerfil.Get(); return(View(model)); } model.Perfis = _busPerfil.Get(); return(View(model)); } catch { return(View()); } }
public void TestMethod_Crud_Cadastro() { var lstUsuario = new List <UsuarioModel>() { new UsuarioModel { Nome = "Jose Pederneiras", Email = "*****@*****.**", Senha = "123456", PerfilId = 1 }, new UsuarioModel() { Nome = "Eder Carlos da Costa", Email = "*****@*****.**", Senha = "1234567", PerfilId = 1 }, new UsuarioModel() { Nome = "João Dória", Email = "*****@*****.**", Senha = "12345678", PerfilId = 2 }, new UsuarioModel() { Nome = "Pablo Picasso", Email = "*****@*****.**", Senha = "123456789", PerfilId = 3 } }; bool retorno = true; foreach (var add in lstUsuario) { var result = _bus.Add(add); if (!result) { retorno = false; } } Assert.AreEqual(true, retorno); }
// POST api/usuario //public void Post([FromBody]string value) //{ //} public HttpResponseMessage Post(Usuario usuario) { if (usuario == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { bus.Add(usuario); return(Request.CreateResponse(HttpStatusCode.OK, usuario)); } catch (Exception) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao incluir usuario")); } }