public Stock(int portfolioId, string code, int nbShares, double investedValue, StockDescription description) { Controllers.DetailedInfosStocksController controller = new Controllers.DetailedInfosStocksController(); Models.DetailedQuoteQueryResultModel infos = controller.RetrieveStockDetailedInfos(code); PortfolioId = portfolioId; Code = infos.Symbol; NumberOfShares = nbShares; InvestedValue = investedValue; UnitaryPrice = InvestedValue / NumberOfShares; Description = description; FillInfos(infos); }
private void BroadcastStockPrice(StockDescription description) { //Broadcast the description only to users that actually need it var portfolioIds = stockServices.GetStockPortfolioIdsHavingStock(description.Code); ////Broadcast to every interected user //List<string> usernames = db.SignalRUsers.Where(u => portfolioIds.Contains(u.PortfolioId)).Select(u => u.UserName).ToList(); //Clients.Users(usernames).updateStockPrice(description); ////Autre methode: on broadcast sur toutes les connexions de tous les usagers qui ont besoin d'etre mis a jour //foreach(var user in db.SignalRUsers.Where(u => portfolioIds.Contains(u.PortfolioId))) //{ // //Explicit loading see https://msdn.microsoft.com/en-us/data/jj574232.aspx // //Load() is not an extension method on Queryable, so it doesn't come together with all the usual LINQ methods. // //If you are using Entity Framework, you need to import the corresponding namespace: System.Data.Entity // db.Entry(user).Collection(u => u.Connections).Query().Where(c => c.Connected == true).Load(); //need using System.Data.Entity; // if(user.Connections !=null) // { // foreach(var connection in user.Connections) // { // Clients.Client(connection.SignalRConnectionId).updateStockPrice(description); // } // } //} foreach(var connection in db.SignalRConnections.Where(c=>portfolioIds.Contains(c.PortfolioId))) { Clients.Client(connection.SignalRConnectionId).updateStockPrice(description); } }
public Stock(Operation operation, StockDescription description) : this(operation.PortfolioId, operation.Code, operation.NumberOfShares, operation.NumberOfShares * operation.Price + operation.Fees, description) { }