public ActionResult DeleteConfirmed(int id) { HistorialPrecioOferta historialPrecioOferta = db.HistorialPrecioOfertas.Find(id); db.HistorialPrecioOfertas.Remove(historialPrecioOferta); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "IdOferta,CantDias,Editorial,TipoOferta,Codigo,Nombre,CodigoProductoServinor,NombreProductoServinor,Descripcion,Precio,CantTarjetasAdicionales,IdEstadoOferta,FechaCarga,FechaInicio,FechaModificacion,FechaFin")] Oferta oferta, int[] idproducts, int[] copias) { oferta.FechaCarga = DateTime.Now; oferta.FechaModificacion = DateTime.Now; oferta.NombreProductoServinor = "DIARIO NORTE"; oferta.CodigoProductoServinor = "000001"; if (ModelState.IsValid) { db.Ofertas.Add(oferta); db.SaveChanges(); var i = 0; foreach (int idprod in idproducts) { ProductoOferta productoOferta = new ProductoOferta(); productoOferta.IdProducto = idprod; productoOferta.IdOferta = oferta.IdOferta; productoOferta.Copias = copias[i]; db.ProductoOfertas.Add(productoOferta); db.SaveChanges(); i = i + 1; } HistorialPrecioOferta hprecio = new HistorialPrecioOferta(); hprecio.FechaInicio = oferta.FechaInicio; hprecio.FechaModificacion = DateTime.Now; hprecio.Precio = oferta.Precio; hprecio.IdOferta = oferta.IdOferta; db.HistorialPrecioOfertas.Add(hprecio); db.SaveChanges(); return(RedirectToAction("Index")); } var a = 0; List <ProductoOferta> prodof = new List <ProductoOferta>(); foreach (int idprod in idproducts) { ProductoOferta productoOferta = new ProductoOferta(); productoOferta.IdProducto = idprod; productoOferta.Producto = db.Productos.Find(idprod); productoOferta.IdOferta = oferta.IdOferta; productoOferta.Copias = copias[a]; prodof.Add(productoOferta); a = a + 1; } ViewBag.prodsacum = prodof; ViewBag.VbEstadosOfertas = db.EstadoOfertas.ToList(); ViewBag.Products = db.Productos.ToList(); return(View(oferta)); }
// GET: HistorialPrecioOfertas/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HistorialPrecioOferta historialPrecioOferta = db.HistorialPrecioOfertas.Find(id); if (historialPrecioOferta == null) { return(HttpNotFound()); } return(View(historialPrecioOferta)); }
// GET: HistorialPrecioOfertas/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HistorialPrecioOferta historialPrecioOferta = db.HistorialPrecioOfertas.Find(id); if (historialPrecioOferta == null) { return(HttpNotFound()); } ViewBag.IdOferta = new SelectList(db.Ofertas, "IdOferta", "Nombre", historialPrecioOferta.IdOferta); return(View(historialPrecioOferta)); }
public ActionResult Edit([Bind(Include = "IdHistorialPrecioOferta,Precio,FechaInicio,IdOferta")] HistorialPrecioOferta historialPrecioOferta) { historialPrecioOferta.FechaModificacion = DateTime.Now; if (ModelState.IsValid) { db.Entry(historialPrecioOferta).State = EntityState.Modified; db.SaveChanges(); Oferta oferta = new Oferta(); oferta = db.Ofertas.Find(historialPrecioOferta.IdOferta); oferta.Precio = historialPrecioOferta.Precio; oferta.FechaInicio = historialPrecioOferta.FechaInicio; db.Entry(oferta).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Create", "HistorialPrecioOfertas", new { idoferta = historialPrecioOferta.IdOferta, msg = "Edición correcta: $ " + historialPrecioOferta.Precio })); } return(View(historialPrecioOferta)); }