Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
 public bool dismissStockOrder(int orderId)
 {
     using (var ctx = new ChocolateCoHQEntities1())
     {
         PendingStockOrders pso = ctx.PendingStockOrders.Find(orderId);
         ctx.PendingStockOrders.Remove(pso);
         int ret = ctx.SaveChanges();
         return(ret > 0);
     }
 }
Beispiel #3
0
        private PendingStockOrderDTO DTO(PendingStockOrders pso)
        {
            PendingStockOrderDTO ret = new PendingStockOrderDTO();

            ret.branch        = pso.branch;
            ret.OrderID       = pso.OrderID;
            ret.ProductID     = pso.ProductID;
            ret.QuantityAsked = pso.QuantityAsked;
            return(ret);
        }
Beispiel #4
0
 public int requestStockHQ(int proposedOrderId, string branch, int productId, int quantityAsked)
 {
     using (var ctx = new ChocolateCoHQEntities1())
     {
         PendingStockOrders pso = new PendingStockOrders();
         pso.branch        = branch;
         pso.ProductID     = productId;
         pso.QuantityAsked = quantityAsked;
         int maxLoggedId = 0, maxPendingId = 0, maxStockLogId = 0;
         if (ctx.OrdersLog.Any())
         {
             maxLoggedId = ctx.OrdersLog.Max(o => o.OrderID);
         }
         if (ctx.PendingStockOrders.Any())
         {
             maxPendingId = ctx.PendingStockOrders.Max(o => o.OrderID);
         }
         if (ctx.StockOrdersLog.Any())
         {
             maxStockLogId = ctx.StockOrdersLog.Max(o => o.OrderId);
         }
         int finalId = Math.Max(maxLoggedId, maxPendingId);
         finalId     = Math.Max(finalId, maxStockLogId);
         finalId     = Math.Max(finalId, proposedOrderId) + 1;
         pso.OrderID = finalId;
         ctx.PendingStockOrders.Add(pso);
         int ret = ctx.SaveChanges();
         if (ret > 0)
         {
             return(finalId);
         }
         else
         {
             return(-1);
         }
     }
 }