public EditarProductoViewModel(Producto producto, IEnumerable<Categoria> categorias) { Id = producto.Id; Nombre = producto.Nombre; Precio = producto.Precio.ToString(); Categorias = new SelectList(categorias, "Id", "Nombre", producto.CategoriaId); TieneImagen = producto.Imagen.Ruta != null; }
public void AgregarLinea(Producto producto) { LineaCarroCompras linea = this.BuscarLinea(producto.Id); if (linea == null) { this.detalle.Add(new LineaCarroCompras { Producto = producto, Cantidad = 1 }); } else { linea.Cantidad += 1; } }
public ActionResult Crear(Producto producto) { if (!ModelState.IsValid) { ViewBag.CategoriaId = new SelectList(context.Categorias.ToList(), "Id", "Nombre"); return this.View(); } context.Productos.Add(producto); context.SaveChanges(); TempData["Mensaje"] = "Se ha creado el producto " + producto.Nombre; return RedirectToAction("index"); }