示例#1
0
 public bool deliverStock(int productId, int quantity)
 {
     using (var ctx = new ChocolateStoreUkEntities2())
     {
         Product p = ctx.Products.Find(productId);
         p.Quantity = p.Quantity + quantity;
         int ret = ctx.SaveChanges();
         return(ret > 0);
     }
 }
示例#2
0
        public List <ShipperDTO> getShippers()
        {
            List <ShipperDTO> list = new List <ShipperDTO>();

            using (var ctx = new ChocolateStoreUkEntities2())
            {
                List <Shipper> shippers = ctx.Shippers.ToList();
                foreach (Shipper s in shippers)
                {
                    list.Add(DTO(s));
                }
                return(list);
            }
        }
示例#3
0
        public List <PendingOrderDTO> getPendingOrdersByClient(int clientId)
        {
            List <PendingOrderDTO> list = new List <PendingOrderDTO>();

            using (var ctx = new ChocolateStoreUkEntities2())
            {
                IEnumerable <PendingOrder> orders = ctx.PendingOrders.Where(o => o.ClientID == clientId);
                foreach (PendingOrder po in orders)
                {
                    list.Add(DTO(po));
                }
                return(list);
            }
        }
示例#4
0
        public List <ProductDTO> getProducts()
        {
            List <ProductDTO> list = new List <ProductDTO>();

            using (var ctx = new ChocolateStoreUkEntities2())
            {
                List <Product> products = ctx.Products.ToList();
                foreach (Product p in products)
                {
                    list.Add(DTO(p));
                }
                return(list);
            }
        }
示例#5
0
        public List <ClientDTO> getClients()
        {
            List <ClientDTO> list = new List <ClientDTO>();

            using (var ctx = new ChocolateStoreUkEntities2())
            {
                List <Client> clients = ctx.Clients.ToList();
                foreach (Client c in clients)
                {
                    list.Add(DTO(c));
                }
                return(list);
            }
        }
示例#6
0
        public List <PendingOrderDTO> getPendingOrders()
        {
            List <PendingOrderDTO> list = new List <PendingOrderDTO>();

            using (var ctx = new ChocolateStoreUkEntities2())
            {
                List <PendingOrder> orders = ctx.PendingOrders.ToList();
                foreach (PendingOrder po in orders)
                {
                    list.Add(DTO(po));
                }
                return(list);
            }
        }
示例#7
0
 //return new order id in hq table
 public int requestStockToHQ(int productId, int quantity)
 {
     using (var ctx = new ChocolateStoreUkEntities2())
     {
         int proposedIdFromOrders  = ctx.Orders.Max(p => p.OrderID);
         int proposedIdFromPending = ctx.PendingOrders.Max(p => p.OrderID);
         HQServiceReference.HQServiceClient client =
             new HQServiceReference.HQServiceClient();
         int newId = client.requestStockHQ(Math.Max(proposedIdFromOrders,
                                                    proposedIdFromPending),
                                           "uk",
                                           productId,
                                           quantity);
         return(newId);
     }
 }
示例#8
0
 public int requestOrder(int clientId, int productId, int quantity, string date, int shipperId)
 {
     using (var ctx = new ChocolateStoreUkEntities2())
     {
         var result = ctx.spCreatePendingOrder(clientId, productId, quantity, System.DateTime.Parse(date), shipperId);
         if (result > 0)
         {
             var orderId = ctx.PendingOrders.Max(p => p.OrderID);
             return(orderId);
         }
         else
         {
             return(-1);
         }
     }
 }
示例#9
0
        public bool dismissOrder(int orderId, string justification)
        {
            using (var ctx = new ChocolateStoreUkEntities2())
            {
                PendingOrder po = ctx.PendingOrders.Find(orderId);
                HQServiceReference.HQServiceClient client =
                    new HQServiceReference.HQServiceClient();

                bool logRet =
                    client.logLocalOrder(po.OrderID, po.ClientID, po.ProductID, po.Date.ToShortDateString(), po.Quantity, po.ShipperID, false, justification);
                logDismissedLocalOrder(po, justification);
                ctx.PendingOrders.Remove(po);
                int ret = ctx.SaveChanges();
                return(logRet && ret > 0);
            }
        }
示例#10
0
 public bool logDismissedLocalOrder(PendingOrder po, string justification)
 {
     using (var ctx = new ChocolateStoreUkEntities2())
     {
         Order o = new Order();
         o.OrderID       = po.OrderID;
         o.ClientID      = po.ClientID;
         o.ProductID     = po.ProductID;
         o.Quantity      = po.Quantity;
         o.Date          = po.Date;
         o.ShipperID     = po.ShipperID;
         o.Accepted      = 0;
         o.Justification = justification;
         ctx.Orders.Add(o);
         int ret = ctx.SaveChanges();
         return(ret > 0);
     }
 }
示例#11
0
        public bool acceptOrder(int orderId)
        {
            using (var ctx = new ChocolateStoreUkEntities2())
            {
                var result = ctx.spConfirmPendingOrder(orderId);
                if (result > 0)
                {
                    Order o = ctx.Orders.Find(orderId);

                    HQServiceReference.HQServiceClient client =
                        new HQServiceReference.HQServiceClient();
                    bool logRet =
                        client.logLocalOrder(o.OrderID, o.ClientID, o.ProductID, o.Date.ToShortDateString(), o.Quantity, o.ShipperID, true, "");
                    return(logRet);
                }
                else
                {
                    return(false);
                }
            }
        }