示例#1
0
        public void ExecuteOrder(int id, float stockValue)
        {
            using (StockServiceModelContainer database = new StockServiceModelContainer())
            {
                StockOrder order = database.StockOrders.Find(id);
                if (order == null)
                {
                    throw new FaultException <OrderNotFoundFault>(new OrderNotFoundFault(id));
                }

                try
                {
                    order.StockValue    = stockValue;
                    order.ExecutionDate = DateTime.UtcNow.ToString();
                    database.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new FaultException <StockServiceFault>(new StockServiceFault(e.Message));
                }

                StockServiceContracts.StockOrder updatedOrder = StockService.ToContractStockOrder(order);
                this.FireOnOrderStatusChange(updatedOrder);
            }
        }
示例#2
0
        public StockServiceContracts.StockOrder OrderStock(string company, int quantity, StockServiceContracts.StockOrder.OrderType type, string email)
        {
            Console.WriteLine("Received request!");

            using (StockServiceModelContainer database = new StockServiceModelContainer())
            {
                database.Database.Connection.Open();

                StockOrder toAdd = new StockOrder()
                {
                    Company     = company,
                    Quantity    = quantity,
                    Email       = email,
                    RequestDate = DateTime.UtcNow.ToString(),
                    Type        = this.GetOrderTypeFromEnum(type, database)
                };

                Console.WriteLine("Created Order!");

                try
                {
                    toAdd = database.StockOrders.Add(toAdd);
                    database.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new FaultException <StockServiceFault>(new StockServiceFault(e.Message));
                }

                StockServiceContracts.StockOrder createdOrder = StockService.ToContractStockOrder(toAdd);
                this.FireOnNewOrder(createdOrder);

                return(createdOrder);
            }
        }