public async Task <IActionResult> Edit(string nombre, string apellido, int idUser) { Usuario usuario = await _context.Usuario.FirstOrDefaultAsync(x => x.IdUsuario == idUser); usuario.Nombre = nombre; usuario.Apellido = apellido; _context.Update(usuario); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(Usuario usuario) { if (ModelState.IsValid) { _context.Update(usuario); await _context.SaveChangesAsync(); return(View("Cuenta")); } return(RedirectToAction("Cuenta")); }
public async Task <IActionResult> Edit([Bind("IdProducto,Nombre,Descripcion,Precio,Stock,Foto,IdCategoria")] Producto producto) { if (ModelState.IsValid) { try { _context.Update(producto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductoExists(producto.IdProducto)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoriaNombre"] = new SelectList(_context.Categoria, "IdCategoria", "Nombre", producto.IdCategoria); return(View(producto)); }
public async Task <IActionResult> addCarrito(Carrito cart) { string idUser = HttpContext.Session.GetString("userID"); if (idUser != null) { int id = Int32.Parse(idUser); var existe = _context.Carrito.Where(x => x.IdUsuario == id && x.IdProducto == cart.IdProducto).Count(); if (existe == 1) { Carrito carrito = await _context.Carrito.FirstOrDefaultAsync(x => x.IdUsuario == id && x.IdProducto == cart.IdProducto); carrito.Cantidad += cart.Cantidad; cart.IdUsuario = Convert.ToInt32(idUser); _context.Update(carrito); } else { cart.IdUsuario = Convert.ToInt32(idUser); // add el los datos a la db await _context.Carrito.AddAsync(cart); } // guardar los cambios realizados a la db int guardado = await _context.SaveChangesAsync(); if (guardado > 0) { TempData["added"] = "success"; return(RedirectToAction("Detalle_Producto", "Home", new { id = cart.IdProducto })); } TempData["added"] = "error"; return(RedirectToAction("Detalle_Producto", "Home", new { id = cart.IdProducto })); } return(RedirectToAction("Login", "Cuenta")); }
public async Task <IActionResult> Cambiar(List <IFormFile> foto1 = null, List <IFormFile> foto2 = null, List <IFormFile> foto3 = null) { //Actiualizacion de la foto 1 if (foto1.Count != 0) { Slider slider = new Slider(); foreach (var item in foto1) { if (item.Length > 0) { using (var stream = new MemoryStream()) { await item.CopyToAsync(stream); slider.Foto = stream.ToArray(); slider.IdSlider = 1; } } } _context.Update(slider); } //Actiualizacion de la foto 2 if (foto2.Count != 0) { Slider slider = new Slider(); foreach (var item in foto2) { if (item.Length > 0) { using (var stream = new MemoryStream()) { await item.CopyToAsync(stream); slider.Foto = stream.ToArray(); slider.IdSlider = 2; } } } _context.Update(slider); } //Actiualizacion de la foto 3 if (foto3.Count != 0) { Slider slider = new Slider(); foreach (var item in foto3) { if (item.Length > 0) { using (var stream = new MemoryStream()) { await item.CopyToAsync(stream); slider.Foto = stream.ToArray(); slider.IdSlider = 3; } } } _context.Update(slider); } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }