public async Task <IActionResult> Edit(int id, [Bind("Id")] UsuarioSupermercado usuarioSupermercado) { if (id != usuarioSupermercado.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(usuarioSupermercado); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsuarioSupermercadoExists(usuarioSupermercado.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(usuarioSupermercado)); }
public async Task <IActionResult> Create([Bind("Id")] UsuarioSupermercado usuarioSupermercado) { if (ModelState.IsValid) { _context.Add(usuarioSupermercado); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(usuarioSupermercado)); }
public async Task <IActionResult> GuardarFavorito(int id) { Usuario usuario = await _userManager.GetUserAsync(User); Supermercado supermercado = await _context.Supermercado.FindAsync(id); UsuarioSupermercado existeusuariosupermercado = _context.UsuarioSupermercado.FirstOrDefault(x => x.IdSupermercado == id); // Si el "Favorito" no existe se crea el favorito if (existeusuariosupermercado == null) { UsuarioSupermercado supermercadoFavorito = new UsuarioSupermercado { Usuario = usuario, Supermercado = supermercado }; if (ModelState.IsValid) { _context.Add(supermercadoFavorito); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { return(NotFound()); } } else { // Si el favorito existe este se pasa como FAVORITO = TRUE al INDEX return(RedirectToAction("Index", new { favoritoSupermercado = "existe" })); } }