public async Task <Producto> AddProductoValor(int id, string cantidad, int importe) { var producto = await GetById(id); ProductoValor pv = new ProductoValor(); //hardcoded until login// pv.IdUserAlta = 1; pv.FechaAlta = DateTime.Now; pv.Activo = true; pv.Importe = importe; pv.Cantidad = cantidad; pv.IdProducto = producto.Id; producto.ProductoValor.Add(pv); try { _context.Update(producto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(producto); }
public ActionResult DeleteConfirmed(int id) { ProductoValor productoValor = db.ProductoValores.Find(id); db.ProductoValores.Remove(productoValor); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,ProductoId,ValorMinimo,ValorMaximo,FechaRegistro")] ProductoValor productoValor) { if (ModelState.IsValid) { db.Entry(productoValor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductoId = new SelectList(db.Productos, "ID", "Descripcion", productoValor.ProductoId); return(View(productoValor)); }
// GET: ProductoValor/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductoValor productoValor = db.ProductoValores.Find(id); if (productoValor == null) { return(HttpNotFound()); } return(View(productoValor)); }
// GET: ProductoValor/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductoValor productoValor = db.ProductoValores.Find(id); if (productoValor == null) { return(HttpNotFound()); } ViewBag.ProductoId = new SelectList(db.Productos, "ID", "Descripcion", productoValor.ProductoId); return(View(productoValor)); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { //Aquí tenemos que usar otra función para pasar el contexto de validación y usar reflection int?productoId = getProductoId(validationContext); if (productoId == null) { return(ValidationResult.Success); } //IEnumerable<ProductoValor> topes = db.ProductoValores.Where(x => x.ProductoId == productoId && x.FechaRegistro == db.ProductoValores.Max(y => y.FechaRegistro)).toList(); ProductoValor topes0 = db.ProductoValores.Where(x => x.ProductoId == productoId && x.ValorMaximo > 0).OrderByDescending(x => x.FechaRegistro).FirstOrDefault(); //ProductoValor topes1 = db.ProductoValores.Where(x => x.ProductoId == productoId && x.FechaRegistro == db.ProductoValores.Max(y => y.FechaRegistro)).SingleOrDefault(); //ProductoValor topes2 = db.ProductoValores.Where(x => x.ProductoId == productoId).Last(); //ProductoValor topes3 = db.ProductoValores.Where(x => x.ProductoId == productoId).OrderByDescending(x => x.FechaRegistro).FirstOrDefault(); //ProductoValor topes4 = db.ProductoValores.Where(x => x.ProductoId == productoId).LastOrDefault(); if (topes0 == null) { return(ValidationResult.Success); } if (topes0.ID <= 0) { return(ValidationResult.Success); } var valor = Convert.ToDouble(value); if (valor >= topes0.ValorMinimo && valor <= topes0.ValorMaximo) { return(ValidationResult.Success); } this.valorMinimo = topes0.ValorMinimo; this.valorMaximo = topes0.ValorMaximo; this.ErrorMessage = FormatErrorMessage(validationContext.DisplayName); ValidationResult validacionError = new ValidationResult(this.ErrorMessageString, new string[] { validationContext.MemberName }); return(validacionError); }