public int acceptStockRequest(int orderId) { using (var ctx = new ChocolateCoHQEntities1()) { UkBranchServiceReference.ProductServiceClient client = new UkBranchServiceReference.ProductServiceClient(); PendingStockOrders pso = ctx.PendingStockOrders.Find(orderId); bool ret = client.deliverStock(pso.ProductID, pso.QuantityAsked); client.Close(); if (ret) { ProductStock ps = ctx.ProductStock.Find(pso.ProductID); ps.quantity = ps.quantity - pso.QuantityAsked; StockOrdersLog sol = new StockOrdersLog(); sol.OrderId = orderId; sol.ProductID = pso.ProductID; sol.branch = pso.branch; sol.Quantity = pso.QuantityAsked; StockOrdersLog errSol = ctx.StockOrdersLog.Add(sol); ctx.PendingStockOrders.Remove(pso); int rowcount = ctx.SaveChanges(); return(rowcount); } else { return(-1); } } }
private ProductStockDTO DTO(ProductStock ps) { ProductStockDTO ret = new ProductStockDTO(); ret.ProductID = ps.ProductID; ret.ProductName = ps.ProductName; ret.ProductType = ps.ProductType; ret.quantity = ps.quantity; return(ret); }