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); } }
private void FireOnOrderStatusChange(StockServiceContracts.StockOrder updatedOrder) { if (this.OnOrderStatusChangeCallbacks.ContainsKey(updatedOrder.Id)) { HashSet <IStockServiceCallback> callbacks = this.OnOrderStatusChangeCallbacks[updatedOrder.Id]; if (callbacks != null) { List <IStockServiceCallback> callbacksToRemove = new List <IStockServiceCallback>(); foreach (IStockServiceCallback callback in callbacks) { try { callback.OnOrderStatusChange(updatedOrder); } catch (Exception e) { Console.WriteLine("Could not access a callback: " + e.Message + "."); Console.WriteLine("Removing it to avoid more errors..."); callbacksToRemove.Add(callback); } } foreach (IStockServiceCallback failingCallback in callbacksToRemove) { callbacks.Remove(failingCallback); } } } }
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); } }
private void FireOnNewOrder(StockServiceContracts.StockOrder order) { List <IStockServiceCallback> callbacksToRemove = new List <IStockServiceCallback>(); foreach (IStockServiceCallback callback in this.OnNewOrderCallbacks) { try { callback.OnNewOrder(order); } catch (Exception e) { Console.WriteLine("Could not access a callback: " + e.Message + "."); Console.WriteLine("Removing it to avoid more errors..."); callbacksToRemove.Add(callback); } } foreach (IStockServiceCallback failingCallback in callbacksToRemove) { this.OnNewOrderCallbacks.Remove(failingCallback); } }