public void SubstractStock(Stock stock, int quantity) { stock.RealQuantity -= quantity; }
public bool HasStock(Stock stock) { return (stock.RealQuantity > 0); }
public bool IsValidStock(Stock stock, int quantity) { return (stock.RealQuantity >= quantity); }
public void AddStock(Stock stock, int quantity) { stock.RealQuantity += quantity; }
public virtual ActionResult ProductStockUpdate(Stock updatedStock) { var Stock = hopeLingerieEntities.Stocks.SingleOrDefault(x => x.StockId == updatedStock.StockId); var stockTomado = Stock.RealQuantity - Stock.VirtualQuantity; var incremento = updatedStock.RealQuantity - Stock.RealQuantity; var auxRealQuantity = updatedStock.RealQuantity; var auxVirtualQuantity = updatedStock.VirtualQuantity + incremento; if (auxVirtualQuantity < 0) { TempData["Error"] = "El stock real no puede ser menor al stock tomado!"; return RedirectToAction("ProductStockUpdate", new { sizeId = Stock.SizeId, colorId = Stock.ColorId }); } Stock.RealQuantity = auxRealQuantity; Stock.VirtualQuantity = auxVirtualQuantity; hopeLingerieEntities.SaveChanges(); return RedirectToAction("ProductColorUpdate", new { productId = Stock.ProductId, colorId = Stock.ColorId }); }
public string ProductColorSizeAdd(FormCollection formCollection) { var sizeId = Convert.ToInt16(formCollection["SizeId_VI"]); var quantity = Convert.ToInt16(formCollection["Quantity_Raw"]); var size = hopeLingerieEntities.Sizes.SingleOrDefault(a=>a.SizeId == sizeId && a.Active); // Actualizo la cantidad real y la cantidad virtual, la virtual es la cantidad suponiendo que se entregaron todos los pedidos de las ventas realizadas hasta el momento. if (size != null) { var colorId = Convert.ToInt16(formCollection["ColorId"]); var color = hopeLingerieEntities.Colors.Single(a => a.ColorId == colorId && a.Active); var sizeExists = (color.Sizes.SingleOrDefault(a=>a.SizeId == size.SizeId && a.Active) != null); if (!sizeExists) { color.Sizes.Add(size); var stock = hopeLingerieEntities.Stocks.SingleOrDefault(x => x.ColorId == colorId && x.ProductId == color.ProductId && x.SizeId == sizeId); if (stock == null) { var newStock = new Stock { ProductId = color.ProductId, SizeId = sizeId, ColorId = colorId, RealQuantity = quantity, VirtualQuantity = quantity }; hopeLingerieEntities.Stocks.AddObject(newStock); if ((newStock.VirtualQuantity >= 0) && (newStock.RealQuantity >= 0)) hopeLingerieEntities.SaveChanges(); } } } return ""; }
/// <summary> /// Create a new Stock object. /// </summary> /// <param name="stockId">Initial value of the StockId property.</param> /// <param name="productId">Initial value of the ProductId property.</param> /// <param name="colorId">Initial value of the ColorId property.</param> /// <param name="sizeId">Initial value of the SizeId property.</param> /// <param name="virtualQuantity">Initial value of the VirtualQuantity property.</param> /// <param name="realQuantity">Initial value of the RealQuantity property.</param> public static Stock CreateStock(global::System.Int32 stockId, global::System.Int32 productId, global::System.Int32 colorId, global::System.Int32 sizeId, global::System.Int32 virtualQuantity, global::System.Int32 realQuantity) { Stock stock = new Stock(); stock.StockId = stockId; stock.ProductId = productId; stock.ColorId = colorId; stock.SizeId = sizeId; stock.VirtualQuantity = virtualQuantity; stock.RealQuantity = realQuantity; return stock; }
/// <summary> /// Deprecated Method for adding a new object to the Stocks EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToStocks(Stock stock) { base.AddObject("Stocks", stock); }