public async Task <IActionResult> Login(string user, string password) { if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password)) { appsContext db = new appsContext(); var usr = db.Usuarios.FirstOrDefault(e => e.Userid == user && e.Pass == password); if (usr != null) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, usr.Userid) }; ClaimsIdentity userIdentity = new ClaimsIdentity(claims, "login"); ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync(principal); return(RedirectToAction("Index", "User")); } else { return(RedirectToAction("Index", new{ message = "Verifica tus datos" })); } } else { return(RedirectToAction("Index", new{ message = "Llena los campos" })); } }
static void Main(string[] args) { //insert var user = new Usuario() { Userid = "ECaporal", Nombre = "Erick Caporal", Pass = "******" }; using (var context = new appsContext()) { context.Usuario.Add(user); context.SaveChanges(); } //delete // var usr = new Usuarios() // { // Id = 10 // }; // using (var context = new appsContext()) // { // context.Usuarios.Remove(usr); // context.SaveChanges(); // } //update // using (var context = new appsContext()) // { // // Retrieve entity by id // // Answer for question #1 // var entity = context.Usuarios.FirstOrDefault(user => user.Id == 1); // // Validate entity is not null // if (entity != null) // { // // Answer for question #2 // // Make changes on entity // entity.Nombre = "Briceño"; // // Update entity in DbSet // context.Usuarios.Update(entity); // // Save changes in database // context.SaveChanges(); // } // } var dbContext = new appsContext(); var usuarios = dbContext.Usuario.ToList(); foreach (var c in usuarios) { System.Console.WriteLine($"id:{c.Id} userid:{c.Userid} nombre:{c.Nombre} pass:{c.Pass} "); } }
public UserController(appsContext context) { _context = context; }