Example #1
0
 public Order(int orderId, string productId, DateTime moment, IWebshopCallback callback)
 {
     OrderId         = orderId;
     ProductId       = productId;
     Moment          = moment;
     WebshopCallback = callback;
 }
Example #2
0
        public void Connect()
        {
            IWebshopCallback currentClient = OperationContext.Current.GetCallbackChannel <IWebshopCallback>();

            if (!clients.Contains(currentClient))
            {
                clients.Add(currentClient);
                clients.ForEach(client => client.NewClientConnected(clients.Count));
            }
        }
Example #3
0
        public void Disconnect()
        {
            IWebshopCallback currentClient = OperationContext.Current.GetCallbackChannel <IWebshopCallback>();

            if (clients.Contains(currentClient))
            {
                clients.Remove(currentClient);
                clients.ForEach(client => client.DisconnectedClient(clients.Count));
            }
        }
Example #4
0
        public void connect()
        {
            IWebshopCallback clientCallback = OperationContext.Current.GetCallbackChannel <IWebshopCallback>();

            clients.Add(clientCallback);

            foreach (IWebshopCallback client in clients)
            {
                client.newClientConnected(clients.Count);
            }
        }
Example #5
0
        public bool BuyProduct(string ProductId)
        {
            IWebshopCallback clientCallback = OperationContext.Current.GetCallbackChannel <IWebshopCallback>();

            foreach (var productsItem in this.productItems)
            {
                if (productsItem.ProductId == ProductId)
                {
                    if (productsItem.Stock > 0)
                    {
                        productsItem.Stock--;
                        foreach (var client in this.connectedClients)
                        {
                            if (client != clientCallback)
                            {
                                client.productSold(productsItem);
                            }
                        }

                        Order order = new Order
                        {
                            ProductId       = productsItem.ProductId,
                            Moment          = DateTime.Now,
                            WebshopCallback = clientCallback
                        };

                        this.orderList.Add(order);
                        // send this order to all shipping clients
                        this.newOrderEvent(order);

                        return(true);
                    }
                }
            }

            return(false);
        }
Example #6
0
        public bool BuyProduct(string productId)
        {
            IWebshopCallback currentClient = OperationContext.Current.GetCallbackChannel <IWebshopCallback>();
            Item             item          = GetProduct(productId);

            if (item.OnSale)
            {
                Order order = new Order(counter++, productId, DateTime.Now, currentClient);
                orders.Add(order);
                if (ShipOrder(order.OrderId))
                {
                    item.Stock--;
                    foreach (IWebshopCallback client in clients)
                    {
                        if (client != currentClient)
                        {
                            client.ProductSold(item);
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }