public IList <ProductStockInfo> GetList() { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,ProductId,ProductItemId,ProductSize,StockNum from ProductStock order by LastUpdatedDate desc " ); IList <ProductStockInfo> list = new List <ProductStockInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString())) { if (reader != null && reader.HasRows) { while (reader.Read()) { ProductStockInfo model = new ProductStockInfo(); model.Id = reader.GetGuid(0); model.ProductId = reader.GetGuid(1); model.ProductItemId = reader.GetGuid(2); model.ProductSize = reader.GetString(3); model.StockNum = reader.GetInt32(4); list.Add(model); } } } return(list); }
public IList <ProductStockInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,ProductId,ProductItemId,ProductSize,StockNum from ProductStock "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } IList <ProductStockInfo> list = new List <ProductStockInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { ProductStockInfo model = new ProductStockInfo(); model.Id = reader.GetGuid(0); model.ProductId = reader.GetGuid(1); model.ProductItemId = reader.GetGuid(2); model.ProductSize = reader.GetString(3); model.StockNum = reader.GetInt32(4); list.Add(model); } } } return(list); }
public ActionResult EditProduct(int pid = -1) { ProductInfo productInfo = AdminProducts.AdminGetProductById(pid); if (productInfo == null) { return(PromptView("商品不存在")); } CategoryInfo vCategoryInfo = AdminCategories.GetCategoryById(productInfo.CateId); string vCateName = ""; if (vCategoryInfo != null) { vCateName = vCategoryInfo.Name; } EditProductModel model = new EditProductModel(); model.PSN = productInfo.PSN; model.CateId = productInfo.CateId; model.CategoryName = vCateName; model.BrandId = productInfo.BrandId; model.ProductName = productInfo.Name; model.ShopPrice = productInfo.ShopPrice; model.MarketPrice = productInfo.MarketPrice; model.CostPrice = productInfo.CostPrice; model.State = productInfo.State; model.IsBest = productInfo.IsBest == 1 ? true : false; model.IsHot = productInfo.IsHot == 1 ? true : false; model.IsNew = productInfo.IsNew == 1 ? true : false; model.DisplayOrder = productInfo.DisplayOrder; model.Weight = productInfo.Weight; model.Description = productInfo.Description; model.BrandName = AdminBrands.GetBrandById(productInfo.BrandId).Name; //库存信息 ProductStockInfo productStockInfo = AdminProducts.GetProductStockByPid(pid); model.StockNumber = productStockInfo.Number; model.StockLimit = productStockInfo.Limit; //商品属性列表 List <ProductAttributeInfo> productAttributeList = Products.GetProductAttributeList(pid); //商品sku项列表 DataTable productSKUItemList = AdminProducts.GetProductSKUItemList(productInfo.Pid); ViewData["pid"] = productInfo.Pid; ViewData["cateId"] = productInfo.CateId; ViewData["categoryName"] = vCateName; ViewData["productAttributeList"] = productAttributeList; ViewData["productSKUItemList"] = productSKUItemList; ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return(View(model)); }
public ProductStockInfo GetModel(object Id) { ProductStockInfo model = null; StringBuilder sb = new StringBuilder(300); sb.Append(@"select top 1 Id,ProductId,ProductItemId,ProductSize,StockNum from ProductStock where Id = @Id " ); SqlParameter parm = new SqlParameter("@Id", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(Id.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString(), parm)) { if (reader != null) { while (reader.Read()) { model = new ProductStockInfo(); model.Id = reader.GetGuid(0); model.ProductId = reader.GetGuid(1); model.ProductItemId = reader.GetGuid(2); model.ProductSize = reader.GetString(3); model.StockNum = reader.GetInt32(4); } } } return(model); }
/// <summary> /// Updates the product stock. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="newAmount">The new amount.</param> public void Update(ProductStockInfo stockInfo, long newAmount) { ServiceClientArgs args = this.serviceClientArgsFactory.GetServiceClientArgs(); using (ProductStockServiceClient client = new ProductStockServiceClient()) { client.Update(stockInfo.ProductCode, newAmount, args); } }
/// <summary> /// Updates the product stock. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="newAmount">The new amount.</param> public void Update(ProductStockInfo stockInfo, long newAmount) { ServiceClientArgs args = this.serviceClientArgsFactory.GetServiceClientArgs(); using (ProductStockServiceClient client = new ProductStockServiceClient()) { client.Update(stockInfo.ProductCode, newAmount, args); } }
public void SetStockInPersistence(ProductStockInfo stockInfo) { var stockDictionary = cache.GetOrCreate <Dictionary <string, int> >(STOCKKEY, (d) => { return(new Dictionary <string, int>()); }); stockDictionary[stockInfo.ProductName] = stockInfo.Stock; }
/// <summary> /// 从IDataReader创建ProductStockInfo /// </summary> public static ProductStockInfo BuildProductStockFromReader(IDataReader reader) { ProductStockInfo productStockInfo = new ProductStockInfo(); productStockInfo.Pid = TypeHelper.ObjectToInt(reader["pid"]); productStockInfo.Number = TypeHelper.ObjectToInt(reader["number"]); productStockInfo.Limit = TypeHelper.ObjectToInt(reader["limit"]); return(productStockInfo); }
/// <summary> /// Gets the specified product stock. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="args">The arguments.</param> /// <returns>The product stock.</returns> public ProductStock Get(ProductStockInfo stockInfo, ServiceClientArgs args) { SiteContext site = Utils.GetExistingSiteContext(args); using (new SiteContextSwitcher(site)) { IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>(); return(stockManager.GetStock(stockInfo)); } }
/// <summary> /// Gets the product stock. /// </summary> /// <param name="stockInfo">The product stock info. Contains info required to get product stock value. /// By default it's product code.</param> /// <returns>The product stock.</returns> public ProductStock GetStock(ProductStockInfo stockInfo) { ServiceClientArgs args = this.serviceClientArgsFactory.GetServiceClientArgs(); using (ProductStockServiceClient client = new ProductStockServiceClient()) { ProductStock stock = client.Get(stockInfo, args); return stock; } }
/// <summary> /// Gets the product stock. /// </summary> /// <param name="stockInfo">The product stock info. Contains info required to get product stock value. /// By default it's product code.</param> /// <returns>The product stock.</returns> public ProductStock GetStock(ProductStockInfo stockInfo) { ServiceClientArgs args = this.serviceClientArgsFactory.GetServiceClientArgs(); using (ProductStockServiceClient client = new ProductStockServiceClient()) { ProductStock stock = client.Get(stockInfo, args); return(stock); } }
/// <summary> /// 获得商品库存 /// </summary> /// <param name="pid">商品id</param> /// <returns></returns> public static ProductStockInfo GetProductStockByPid(int pid) { ProductStockInfo productStockInfo = null; IDataReader reader = BrnShop.Core.BSPData.RDBS.GetProductStockByPid(pid); if (reader.Read()) { productStockInfo = BuildProductStockFromReader(reader); } reader.Close(); return(productStockInfo); }
/// <summary> /// Updates the specified stock info. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="expression">The expression.</param> public void Update(ProductStockInfo stockInfo, Expression <Func <long, long> > expression) { Func <long, long> func = expression.Compile(); ServiceClientArgs args = this.serviceClientArgsFactory.GetServiceClientArgs(); using (ProductStockServiceClient client = new ProductStockServiceClient()) { ProductStock stock = client.Get(stockInfo, args); long newStock = func(stock.Stock); client.Update(stockInfo.ProductCode, newStock, args); } }
/// <summary> /// 获得商品库存列表 /// </summary> /// <param name="pidList">商品id列表</param> /// <returns></returns> public static List <ProductStockInfo> GetProductStockList(string pidList) { List <ProductStockInfo> productStockList = new List <ProductStockInfo>(); IDataReader reader = BrnShop.Core.BSPData.RDBS.GetProductStockList(pidList); while (reader.Read()) { ProductStockInfo productStockInfo = BuildProductStockFromReader(reader); productStockList.Add(productStockInfo); } reader.Close(); return(productStockList); }
public IList <ProductStockInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select count(*) from ProductStock "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString(), cmdParms); if (totalRecords == 0) { return(new List <ProductStockInfo>()); } sb.Clear(); int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, Id,ProductId,ProductItemId,ProductSize,StockNum from ProductStock " ); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex); IList <ProductStockInfo> list = new List <ProductStockInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { ProductStockInfo model = new ProductStockInfo(); model.Id = reader.GetGuid(1); model.ProductId = reader.GetGuid(2); model.ProductItemId = reader.GetGuid(3); model.ProductSize = reader.GetString(4); model.StockNum = reader.GetInt32(5); list.Add(model); } } } return(list); }
/// <summary> /// Processes the order. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// The result. /// </returns> public override string ProcessOrder(Order order, [NotNull] IDictionary <string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "orderlineid").Value, "Order line ID should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "quantity").Value, "Quantity should be passed as parameter."); long orderLineId = long.Parse(parameters["orderlineid"].ToString()); long quantity = long.Parse(parameters["quantity"].ToString()); // Resolving of the OrderLine. OrderLine orderLine = order.OrderLines.Single(ol => ol.Alias == orderLineId); Assert.IsNotNull(orderLine, "Cannot resolve order line"); this.SetOrderStates(order); // Resolving of the Stock. ProductStockInfo productStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; long productStock = this.ProductStockManager.GetStock(productStockInfo).Stock; long stockSubtrahend = (long)(quantity - orderLine.LineItem.Quantity); if (productStock < stockSubtrahend) { return(CustomResults.OutOfStock.ToString()); } // Updating of the stock this.ProductStockManager.Update(productStockInfo, productStock - stockSubtrahend); this.FormattedMessageForOldOrderLine = this.CreateFormattedMessage(orderLine); // Update order line orderLine.LineItem.Quantity = quantity; this.FormattedMessageForNewOrderLine = this.CreateFormattedMessage(orderLine); // Recalculate taxable amount order = this.UpdateTaxesForOrder(order, orderLine); // Saving of the Order this.OrderManager.Save(order); return(SuccessfulResult); }
/// <summary> /// Gets the product stock. /// </summary> /// <param name="stockInfo">The product stock info. Contains info required to get product stock value. /// By default it's product code.</param> /// <returns>The product stock.</returns> public virtual DomainModel.Products.ProductStock GetStock(ProductStockInfo stockInfo) { ReaderWriterLockSlim readerWriterLock = GetLock(stockInfo); readerWriterLock.EnterReadLock(); try { DomainModel.Products.ProductStock stock = this.productRepository.Get<DomainModel.Products.ProductStock>(stockInfo.ProductCode); return stock; } finally { readerWriterLock.ExitReadLock(); } }
/// <summary> /// Gets the product stock. /// </summary> /// <param name="stockInfo">The product stock info. Contains info required to get product stock value. /// By default it's product code.</param> /// <returns>The product stock.</returns> public virtual DomainModel.Products.ProductStock GetStock(ProductStockInfo stockInfo) { ReaderWriterLockSlim readerWriterLock = GetLock(stockInfo); readerWriterLock.EnterReadLock(); try { DomainModel.Products.ProductStock stock = this.productRepository.Get <DomainModel.Products.ProductStock>(stockInfo.ProductCode); return(stock); } finally { readerWriterLock.ExitReadLock(); } }
/// <summary> /// Updates the specified product stock. /// </summary> /// <param name="code">The code.</param> /// <param name="newAmount">The new amount.</param> /// <param name="args">The arguments.</param> public void Update(string code, long newAmount, ServiceClientArgs args) { ProductStockInfo stockInfo = new ProductStockInfo { ProductCode = code }; SiteContext site = Utils.GetExistingSiteContext(args); using (new SiteContextSwitcher(site)) { IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>(); stockManager.Update(stockInfo, newAmount); } }
/// <summary> /// Processes the order. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// The result. /// </returns> public override string ProcessOrder(Order order, [NotNull] IDictionary<string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "orderlineid").Value, "Order line ID should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "quantity").Value, "Quantity should be passed as parameter."); long orderLineId = long.Parse(parameters["orderlineid"].ToString()); long quantity = long.Parse(parameters["quantity"].ToString()); // Resolving of the OrderLine. OrderLine orderLine = order.OrderLines.Single(ol => ol.Alias == orderLineId); Assert.IsNotNull(orderLine, "Cannot resolve order line"); this.SetOrderStates(order); // Resolving of the Stock. ProductStockInfo productStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; long productStock = this.ProductStockManager.GetStock(productStockInfo).Stock; long stockSubtrahend = (long)(quantity - orderLine.LineItem.Quantity); if (productStock < stockSubtrahend) { return CustomResults.OutOfStock.ToString(); } // Updating of the stock this.ProductStockManager.Update(productStockInfo, productStock - stockSubtrahend); this.FormattedMessageForOldOrderLine = this.CreateFormattedMessage(orderLine); // Update order line orderLine.LineItem.Quantity = quantity; this.FormattedMessageForNewOrderLine = this.CreateFormattedMessage(orderLine); // Recalculate taxable amount order = this.UpdateTaxesForOrder(order, orderLine); // Saving of the Order this.OrderManager.Save(order); return SuccessfulResult; }
private void nButton11_BIDMouseEnter(object sender, EventArgs e) { foreach (Control a in this.Controls) { if (a is ProductStockInfo) { Controls.Remove(a); } } ProductInfo = new ProductStockInfo(); ProductInfo.Location = new Point(300, 300); ProductInfo.Name = "ProductInfo"; this.Controls.Add(ProductInfo); ProductInfo.Show(); ProductInfo.BringToFront(); }
/* * @StockID INT OUTPUT, * @ProductCode VARCHAR(32), * @HouseID INT, * @TypeID SMALLINT, * @Stock INT, * @ChangeTime SMALLDATETIME, * @LogType INT */ internal int ProductStock_Deal(ProductStockInfo info) { var sql = "ProductStock_Deal"; var cmd = dbw.GetStoredProcCommand(sql); dbw.AddOutParameter(cmd, "StockID", DbType.Int32, 4); dbw.AddInParameter(cmd, "ProductCode", DbType.String, info.ProductCode); dbw.AddInParameter(cmd, "HouseID", DbType.Int32, info.HouseID); dbw.AddInParameter(cmd, "TypeID", DbType.Int32, info.TypeID); dbw.AddInParameter(cmd, "Stock", DbType.Int32, info.Stock); dbw.AddInParameter(cmd, "ChangeTime", DbType.DateTime, info.ChangeTime); dbw.AddInParameter(cmd, "LogType", DbType.Int32, info.LogType); dbw.ExecuteNonQuery(cmd); return(int.Parse(dbw.GetParameterValue(cmd, "StockID").ToString())); }
/// <summary> /// Processes the order. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// The process order. /// </returns> public override string ProcessOrder([NotNull] Order order, [NotNull] IDictionary <string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "productcode").Value, "Product code should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "quantity").Value, "Quantity should be passed as parameter."); string productCode = parameters["productcode"].ToString(); Assert.IsTrue(productCode != string.Empty, "Product code must not be empty"); long quantity = long.Parse(parameters["quantity"].ToString()); Assert.IsNotNull(this.orderLineFactory, "orderLineFactory cannot be null."); OrderLine orderLine = this.orderLineFactory.CreateOrderLineFromOrder(order, productCode, quantity); Assert.IsNotNull(orderLine, "Cannot construct new order line from the available parameters."); this.CreateFormattedMessage(orderLine); this.SetOrderStates(order); ProductStockInfo productStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; long stock = this.productStockManager.GetStock(productStockInfo).Stock; if (stock < orderLine.LineItem.Quantity) { return(CustomResults.OutOfStock.ToString()); } this.productStockManager.Update(productStockInfo, stock - (long)orderLine.LineItem.Quantity); order.OrderLines.Add(orderLine); // Recalculate taxable amount. order = this.UpdateTaxesForOrder(order, orderLine); this.merchantOrderManager.Save(order); return(SuccessfulResult); }
/// <summary> /// Updates the specified stock info. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="expression">The expression.</param> public void Update(ProductStockInfo stockInfo, Expression <Func <long, long> > expression) { ReaderWriterLockSlim readerWriterLock = GetLock(stockInfo); readerWriterLock.EnterWriteLock(); try { DomainModel.Products.ProductStock stock = this.productRepository.Get <DomainModel.Products.ProductStock>(stockInfo.ProductCode); Func <long, long> func = expression.Compile(); stock.Stock = func(stock.Stock); this.productRepository.Update(stock); } finally { readerWriterLock.ExitWriteLock(); } }
/// <summary> /// Processes the order. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// The result. /// </returns> public override string ProcessOrder([NotNull] Order order, [NotNull] IDictionary <string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "orderline").Value, "Order line should be passed as parameter."); OrderLine orderLine = parameters["orderline"] as OrderLine; Assert.IsNotNull(orderLine, "Cannot resolve order line"); Assert.IsTrue(order.OrderLines.Count > 1, "Cannot remove the last order line."); this.SetOrderStates(order); this.CreateFormattedMessage(orderLine); // Resolving of the Stock. ProductStockInfo currentProductStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; ProductStock productStock = this.productStockManager.GetStock(currentProductStockInfo); Assert.IsNotNull(productStock, "This is unknown product"); long currentProductStock = productStock.Stock; // Updating of the stock. this.productStockManager.Update(currentProductStockInfo, currentProductStock + (long)orderLine.LineItem.Quantity); // Recalculate taxable amount. order = this.UpdateTaxesForOrder(order, orderLine); // Remove order line. order.OrderLines.Remove(orderLine); // Save order this.merchantOrderManager.Save(order); return(SuccessfulResult); }
public int Insert(ProductStockInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"insert into ProductStock (ProductId,ProductItemId,ProductSize,StockNum) values (@ProductId,@ProductItemId,@ProductSize,@StockNum) " ); SqlParameter[] parms = { new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier), new SqlParameter("@ProductItemId", SqlDbType.UniqueIdentifier), new SqlParameter("@ProductSize", SqlDbType.VarChar,10), new SqlParameter("@StockNum", SqlDbType.Int) }; parms[0].Value = model.ProductId; parms[1].Value = model.ProductItemId; parms[2].Value = model.ProductSize; parms[3].Value = model.StockNum; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString(), parms)); }
/// <summary> /// Processes the specified order. /// </summary> /// <typeparam name="T">The order type.</typeparam> /// <param name="order">The order instance.</param> protected override void Process <T>(T order) { if (order.OrderLines.IsNullOrEmpty()) { return; } foreach (OrderLine indexOrderLine in order.OrderLines) { if (!(indexOrderLine.Product is Product)) { continue; } IProductStockManager stockManager = Context.Entity.Resolve <IProductStockManager>(); ProductStockInfo stockInfo = new ProductStockInfo { ProductCode = indexOrderLine.Product.Code }; OrderLine line = indexOrderLine; stockManager.Update(stockInfo, s => s - line.Quantity); } }
public int Update(ProductStockInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"update ProductStock set ProductId = @ProductId,ProductItemId = @ProductItemId,ProductSize = @ProductSize,StockNum = @StockNum where Id = @Id " ); SqlParameter[] parms = { new SqlParameter("@Id", SqlDbType.UniqueIdentifier), new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier), new SqlParameter("@ProductItemId", SqlDbType.UniqueIdentifier), new SqlParameter("@ProductSize", SqlDbType.VarChar,10), new SqlParameter("@StockNum", SqlDbType.Int) }; parms[0].Value = model.Id; parms[1].Value = model.ProductId; parms[2].Value = model.ProductItemId; parms[3].Value = model.ProductSize; parms[4].Value = model.StockNum; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, sb.ToString(), parms)); }
public override string ProcessOrder([NotNull] Order order, IDictionary<string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "orderlineid").Value, "Order line ID should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "productcode").Value, "Product code should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "quantity").Value, "Quantity should be passed as parameter."); string productCode = parameters["productcode"].ToString(); Assert.IsTrue(productCode != string.Empty, "Product code must not be empty"); long quantity = long.Parse(parameters["quantity"].ToString()); long orderLineId = long.Parse(parameters["orderlineid"].ToString()); // Resolving of the OrderLine. OrderLine orderLine = order.OrderLines.Single(ol => ol.Alias == orderLineId); Assert.IsNotNull(orderLine, "Cannot resolve order line"); this.SetOrderStates(order); // Resolving of the Stock. ProductStockInfo currentProductStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; long currentProductStock = this.productStockManager.GetStock(currentProductStockInfo).Stock; ProductStockInfo newProductStockInfo = new ProductStockInfo { ProductCode = productCode }; long newProductStock = this.productStockManager.GetStock(newProductStockInfo).Stock; if (newProductStock < quantity) { return CustomResults.OutOfStock.ToString(); } // Updating of the stock this.productStockManager.Update(currentProductStockInfo, currentProductStock + (long)orderLine.LineItem.Quantity); this.productStockManager.Update(newProductStockInfo, newProductStock - quantity); this.FormattedMessageForOldOrderLine = this.CreateFormattedMessage(orderLine); // Updating of the LineItem Assert.IsNotNull(this.orderLineFactory, "OrderLineFactory cannot be null."); LineItem newLineItem = this.orderLineFactory.CreateLineItemFromOrder(order, productCode, quantity); orderLine.LineItem.CopyLineItemFrom(newLineItem); this.FormattedMessageForNewOrderLine = this.CreateFormattedMessage(orderLine); // Recalculate taxable amount. order = this.UpdateTaxesForOrder(order, orderLine); // Saving of the Order) this.merchantOrderManager.Save(order); return SuccessfulResult; }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(ProductStockInfo model) { return(dal.Insert(model)); }
/// <summary> /// Updates the product stock. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="newAmount">The new amount.</param> public virtual void Update(ProductStockInfo stockInfo, long newAmount) { this.Update(stockInfo, a => newAmount); }
/// <summary> /// Updates the specified stock info. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="expression">The expression.</param> public void Update(ProductStockInfo stockInfo, Expression<Func<long, long>> expression) { ReaderWriterLockSlim readerWriterLock = GetLock(stockInfo); readerWriterLock.EnterWriteLock(); try { DomainModel.Products.ProductStock stock = this.productRepository.Get<DomainModel.Products.ProductStock>(stockInfo.ProductCode); Func<long, long> func = expression.Compile(); stock.Stock = func(stock.Stock); this.productRepository.Update(stock); } finally { readerWriterLock.ExitWriteLock(); } }
public override string ProcessOrder([NotNull] Order order, IDictionary <string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "orderlineid").Value, "Order line ID should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "productcode").Value, "Product code should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "quantity").Value, "Quantity should be passed as parameter."); string productCode = parameters["productcode"].ToString(); Assert.IsTrue(productCode != string.Empty, "Product code must not be empty"); long quantity = long.Parse(parameters["quantity"].ToString()); long orderLineId = long.Parse(parameters["orderlineid"].ToString()); // Resolving of the OrderLine. OrderLine orderLine = order.OrderLines.Single(ol => ol.Alias == orderLineId); Assert.IsNotNull(orderLine, "Cannot resolve order line"); this.SetOrderStates(order); // Resolving of the Stock. ProductStockInfo currentProductStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; long currentProductStock = this.productStockManager.GetStock(currentProductStockInfo).Stock; ProductStockInfo newProductStockInfo = new ProductStockInfo { ProductCode = productCode }; long newProductStock = this.productStockManager.GetStock(newProductStockInfo).Stock; if (newProductStock < quantity) { return(CustomResults.OutOfStock.ToString()); } // Updating of the stock this.productStockManager.Update(currentProductStockInfo, currentProductStock + (long)orderLine.LineItem.Quantity); this.productStockManager.Update(newProductStockInfo, newProductStock - quantity); this.FormattedMessageForOldOrderLine = this.CreateFormattedMessage(orderLine); // Updating of the LineItem Assert.IsNotNull(this.orderLineFactory, "OrderLineFactory cannot be null."); LineItem newLineItem = this.orderLineFactory.CreateLineItemFromOrder(order, productCode, quantity); orderLine.LineItem.CopyLineItemFrom(newLineItem); this.FormattedMessageForNewOrderLine = this.CreateFormattedMessage(orderLine); // Recalculate taxable amount. order = this.UpdateTaxesForOrder(order, orderLine); // Saving of the Order) this.merchantOrderManager.Save(order); return(SuccessfulResult); }
/// <summary> /// Gets the lock. /// </summary> /// <param name="stockInfo">The product stock info.</param> /// <returns> /// The lock. /// </returns> private static ReaderWriterLockSlim GetLock(ProductStockInfo stockInfo) { return Locks[(stockInfo.ProductCode.GetHashCode() & int.MaxValue) % Locks.Length]; }
/// <summary> /// Gets the lock. /// </summary> /// <param name="stockInfo">The product stock info.</param> /// <returns> /// The lock. /// </returns> private static ReaderWriterLockSlim GetLock(ProductStockInfo stockInfo) { return(Locks[(stockInfo.ProductCode.GetHashCode() & int.MaxValue) % Locks.Length]); }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(ProductStockInfo model) { return(dal.Update(model)); }
/// <summary> /// Updates the product stock. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="newAmount">The new amount.</param> public virtual void Update(ProductStockInfo stockInfo, long newAmount) { this.Update(stockInfo, a => newAmount); }
/// <summary> /// Processes the order. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// The process order. /// </returns> public override string ProcessOrder([NotNull] Order order, [NotNull] IDictionary<string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "productcode").Value, "Product code should be passed as parameter."); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "quantity").Value, "Quantity should be passed as parameter."); string productCode = parameters["productcode"].ToString(); Assert.IsTrue(productCode != string.Empty, "Product code must not be empty"); long quantity = long.Parse(parameters["quantity"].ToString()); Assert.IsNotNull(this.orderLineFactory, "orderLineFactory cannot be null."); OrderLine orderLine = this.orderLineFactory.CreateOrderLineFromOrder(order, productCode, quantity); Assert.IsNotNull(orderLine, "Cannot construct new order line from the available parameters."); this.CreateFormattedMessage(orderLine); this.SetOrderStates(order); ProductStockInfo productStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; long stock = this.productStockManager.GetStock(productStockInfo).Stock; if (stock < orderLine.LineItem.Quantity) { return CustomResults.OutOfStock.ToString(); } this.productStockManager.Update(productStockInfo, stock - (long)orderLine.LineItem.Quantity); order.OrderLines.Add(orderLine); // Recalculate taxable amount. order = this.UpdateTaxesForOrder(order, orderLine); this.merchantOrderManager.Save(order); return SuccessfulResult; }
/// <summary> /// Processes the order. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// The result. /// </returns> public override string ProcessOrder([NotNull] Order order, [NotNull] IDictionary<string, object> parameters) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.IsNotNull(parameters.FirstOrDefault(p => p.Key == "orderline").Value, "Order line should be passed as parameter."); OrderLine orderLine = parameters["orderline"] as OrderLine; Assert.IsNotNull(orderLine, "Cannot resolve order line"); Assert.IsTrue(order.OrderLines.Count > 1, "Cannot remove the last order line."); this.SetOrderStates(order); this.CreateFormattedMessage(orderLine); // Resolving of the Stock. ProductStockInfo currentProductStockInfo = new ProductStockInfo { ProductCode = orderLine.LineItem.Item.Code }; ProductStock productStock = this.productStockManager.GetStock(currentProductStockInfo); Assert.IsNotNull(productStock, "This is unknown product"); long currentProductStock = productStock.Stock; // Updating of the stock. this.productStockManager.Update(currentProductStockInfo, currentProductStock + (long)orderLine.LineItem.Quantity); // Recalculate taxable amount. order = this.UpdateTaxesForOrder(order, orderLine); // Remove order line. order.OrderLines.Remove(orderLine); // Save order this.merchantOrderManager.Save(order); return SuccessfulResult; }
/// <summary> /// Updates the specified stock info. /// </summary> /// <param name="stockInfo">The stock info.</param> /// <param name="expression">The expression.</param> public void Update(ProductStockInfo stockInfo, Expression<Func<long, long>> expression) { Func<long, long> func = expression.Compile(); ServiceClientArgs args = this.serviceClientArgsFactory.GetServiceClientArgs(); using (ProductStockServiceClient client = new ProductStockServiceClient()) { ProductStock stock = client.Get(stockInfo, args); long newStock = func(stock.Stock); client.Update(stockInfo.ProductCode, newStock, args); } }
public override Sitecore.Ecommerce.DomainModel.Products.ProductStock GetStock(ProductStockInfo stockInfo) { var stock = base.GetStock(stockInfo); var extended = stock as ProductStock; if (extended == null) { return(stock); } /** * Look at a site attribute to see if we should use an alternate stock value. Real-world mapping to * regional warehouses would likely require more work here. Depending on your inventory management approach, * you might also need to override Update methods to ensure the right stock value is decremented as well on update. */ if (ShopContext.InnerSite.Properties["stockRegion"] == "alternate") { extended.Stock = extended.RegionSpecificStock; } /** * Check to see if stock levels are below a product-specific threshhold for considering the product out of stock. * Allows for a stock "buffer" but may result in lost sales. */ if (extended.OutOfStockThreshold > 0 && stock.Stock <= extended.OutOfStockThreshold) { extended.Stock = 0; } return(extended); }