Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 3
0
 public void updateBranchStock(List <int> productsStock)
 {
     using (ChocolateCoHQEntities1 ctx = new ChocolateCoHQEntities1())
     {
         for (int i = 0; i < productsStock.Count; i += 2)
         {
             var p = ctx.ProductStock.Find(productsStock.ElementAt(i));
             p.quantity_uk = productsStock.ElementAt(i + 1);
         }
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public List <StockOrderLogDTO> getStockOrderLogs()
        {
            List <StockOrderLogDTO> list = new List <StockOrderLogDTO>();

            using (var ctx = new ChocolateCoHQEntities1())
            {
                List <StockOrdersLog> sologlist = ctx.StockOrdersLog.ToList();
                foreach (StockOrdersLog sol in sologlist)
                {
                    list.Add(DTO(sol));
                }
                return(list);
            }
        }
Ejemplo n.º 5
0
        public List <OrdersLogDTO> getOrdersLogs()
        {
            List <OrdersLogDTO> list = new List <OrdersLogDTO>();

            using (var ctx = new ChocolateCoHQEntities1())
            {
                List <OrdersLog> ologlist = ctx.OrdersLog.ToList();
                foreach (OrdersLog olog in ologlist)
                {
                    list.Add(DTO(olog));
                }
                return(list);
            }
        }
Ejemplo n.º 6
0
        public List <BranchDTO> getBranches()
        {
            List <BranchDTO> list = new List <BranchDTO>();

            using (var ctx = new ChocolateCoHQEntities1())
            {
                List <Branches> brlist = ctx.Branches.ToList();
                foreach (Branches br in brlist)
                {
                    list.Add(DTO(br));
                }
                return(list);
            }
        }
Ejemplo n.º 7
0
        public List <ProductStockDTO> getProductStocks()
        {
            List <ProductStockDTO> list = new List <ProductStockDTO>();

            using (var ctx = new ChocolateCoHQEntities1())
            {
                List <ProductStock> pslist = ctx.ProductStock.ToList();
                foreach (ProductStock ps in pslist)
                {
                    list.Add(DTO(ps));
                }
                return(list);
            }
        }
Ejemplo n.º 8
0
        public List <PendingStockOrderDTO> getPendingStockOrders()
        {
            List <PendingStockOrderDTO> list = new List <PendingStockOrderDTO>();

            using (var ctx = new ChocolateCoHQEntities1())
            {
                List <PendingStockOrders> psos = ctx.PendingStockOrders.ToList();
                foreach (PendingStockOrders pso in psos)
                {
                    list.Add(DTO(pso));
                }
                return(list);
            }
        }
Ejemplo n.º 9
0
 public bool logLocalOrder(int orderId, int localClientId, int productId, string date, int quantity, int localShipperId, bool isAccepted, string justification)
 {
     using (var ctx = new ChocolateCoHQEntities1())
     {
         OrdersLog ol = new OrdersLog();
         ol.OrderID        = orderId;
         ol.LocalClientID  = localClientId;
         ol.ProductID      = productId;
         ol.Date           = DateTime.Parse(date);
         ol.Quantity       = quantity;
         ol.LocalShipperID = localShipperId;
         ol.Accepted       = (short)(isAccepted ? 1 : 0);
         ol.Justification  = justification;
         ctx.OrdersLog.Add(ol);
         int ret = ctx.SaveChanges();
         return(ret > 0);
     }
 }
Ejemplo n.º 10
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);
         }
     }
 }