public async Task <IActionResult> Login([FromForm] PerfilViewModel model) { PerfilViewModel perfil = null; using (var conn = _conexao.AbrirConexao()) { string queryQuery = $"SELECT * FROM PERFIL WHERE LOGIN = '******' AND SENHA = '{model.Senha}'; "; perfil = conn.QueryFirst <PerfilViewModel>(queryQuery); } if (perfil != null) { var userClaims = new List <Claim>() { new Claim(ClaimValueTypes.String, perfil.Id_Perfil.ToString(), "Id_Perfil"), new Claim(ClaimValueTypes.String, perfil.Nome, "Nome"), new Claim(ClaimValueTypes.String, perfil.Email, "Email"), new Claim(ClaimValueTypes.String, perfil.Login, "Login") }; var minhaIdentidade = new ClaimsIdentity(userClaims, "Perfil"); var userPrincipal = new ClaimsPrincipal(new[] { minhaIdentidade }); await HttpContext.SignInAsync(userPrincipal); return(RedirectToAction("Index", "Home")); } ViewBag.Mensagem = "Credenciais invalidas!"; return(View(model)); }
public ActionResult Index(PerfilViewModel pvm) { if (!ModelState.IsValid) { return(View(pvm)); } Usuarios usuarioBD = us.TraerPerfilDelUsuario((int)Session["ID"]); if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0) { //TODO: Agregar validacion para confirmar que el archivo es una imagen if (!string.IsNullOrEmpty(pvm.Foto)) { //recordar eliminar la foto anterior si tenia if (!string.IsNullOrEmpty(usuarioBD.Foto)) { ImagenesUtility.Borrar(usuarioBD.Foto); } //creo un nombre significativo en este caso apellidonombre pero solo un caracter del nombre, ejemplo BatistutaG string nombreSignificativo = pvm.Nombre + pvm.Apellido; //Guardar Imagen string pathRelativoImagen = ImagenesUtility.Guardar(Request.Files[0], nombreSignificativo); usuarioBD.Foto = pathRelativoImagen; } } usuarioBD.Nombre = pvm.Nombre; usuarioBD.Apellido = pvm.Apellido; usuarioBD.FechaNacimiento = pvm.FechaNacimiento; us.ActualizarPerfilDelUsuario(usuarioBD); return(Redirect("/Home/Index")); }
public IHttpActionResult Post([FromBody] PerfilViewModel perfilVM) { var result = new GenericResult <PerfilViewModel>(); var validatorResult = _validator.Validate(perfilVM); if (validatorResult.IsValid) { try { result.Result = _perfilApplication.Cadastrar(perfilVM); result.Success = true; return(Content(HttpStatusCode.Created, result)); } catch (Exception ex) { result.Errors = new string[] { ex.Message }; return(Content(HttpStatusCode.InternalServerError, result)); } } else { result.Errors = validatorResult.GetErrors(); return(Content(HttpStatusCode.BadRequest, result)); } }
protected void Salvar(object sender, EventArgs e) { var perfil = new PerfilViewModel(); bool novo = true; int id = 0; int.TryParse(Request.QueryString["Id"], out id); if (id > 0) { perfil = Index.consumer.GetById(id); novo = perfil == null; } perfil.Ativo = ChkAtivo.Checked; perfil.Nome = TxtNome.Text; if (novo) { Index.consumer.Add(perfil); } else { Index.consumer.Update(perfil); } Response.Redirect("Index"); }
public ActionResult Gravar(PerfilViewModel perfil) { var gravarResult = perfilAppService.Gravar(perfil); object retorno; if (gravarResult.IsValid) { retorno = new { Mensagem = "Registro Gravado com Sucesso", Erro = false }; } else { retorno = new { Mensagem = RenderizeErros(gravarResult), Erro = true }; } return Json(retorno, JsonRequestBehavior.AllowGet); }