public IActionResult ShowStockInfo(int id) { var stocks = _dataContext.Stocks.ToList(); _currentStock = stocks.FirstOrDefault(p => p.Id == id); StockInfoViewModel model = new StockInfoViewModel(); var result = from stock in _dataContext.Stocks join company in _dataContext.Companies on stock.CompanyId equals company.Id join country in _dataContext.Countries on company.CountryId equals country.Id select new { Id = stock.Id, CurrentPrice = stock.CurrentPrice, YearPorfitability = stock.YearPorfitability, FullName = company.FullName, ShortName = company.ShortName, CountryName = country.Name }; foreach (var r in result) { if (r.Id == _currentStock.Id) { model.StockId = r.Id; model.CurrentPrice = r.CurrentPrice; model.YearProfitability = r.YearPorfitability; model.CompanyFullName = r.FullName; model.CompanyShortName = r.ShortName; model.CountryName = r.CountryName; } } return(View(model)); }
public IActionResult DealSuccess(StockInfoViewModel model) { var users = _dataContext.Users.ToList(); User user = users.FirstOrDefault(p => p.UserName == User.Identity.Name); var wallets = _dataContext.Wallets.ToList(); Wallet wallet = wallets.FirstOrDefault(p => p.UserId == user.Id); int stockId = _currentStock.Id; var stocks = _dataContext.Stocks.ToList(); Stock stock = stocks.FirstOrDefault(p => p.Id == stockId); if (wallet.TotalSum >= model.StockNumber * _currentStock.CurrentPrice) { Deal deal = new Deal { DealDate = DateTime.Now, StockId = _currentStock.Id, Stock = stock, StockNumber = model.StockNumber, WalletId = wallet.Id, Wallet = wallet, CurrentStockPrice = _currentStock.CurrentPrice, IsBought = true }; _dataContext.Deals.Add(deal); wallet.TotalSum -= model.StockNumber * _currentStock.CurrentPrice; _dataContext.SaveChanges(); } return(View()); }
/// <summary> /// Gets the curent axis category X template. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private DataTemplate GetCurentAxisCategoryXTemplate(StockInfoViewModel item) { DataTemplate dataTemplate = null; if (AxisCategoryXTemplateSelector != null) { dataTemplate = AxisCategoryXTemplateSelector.SelectTemplate(DataContext, this); } if (dataTemplate == null && AxisCategoryXTemplate != null) { dataTemplate = AxisCategoryXTemplate; } return(dataTemplate); }
/// <summary> /// Gets the curent series template. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private DataTemplate GetCurentSeriesTemplate(StockInfoViewModel item) { DataTemplate dataTemplate = null; // get data template if (this.SeriesTemplateSelector != null) { dataTemplate = this.SeriesTemplateSelector.SelectTemplate(item, this); } if (dataTemplate == null && this.SeriesTemplate != null) { dataTemplate = this.SeriesTemplate; } return(dataTemplate); }
/// <summary> /// Modifies the source data before passing it to the target for display in the UI. /// </summary> /// <param name="value">The source data being passed to the target.</param> /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param> /// <param name="parameter">An optional parameter to be used in the converter logic.</param> /// <param name="culture">The culture of the conversion.</param> /// <returns> /// The value to be passed to the target dependency property. /// </returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { StockInfoViewModel sivm = value as StockInfoViewModel; if (sivm == null) { return(false); } if (sivm.Parent == null) { return(false); } if (sivm.Parent.SelectedStock == null) { return(false); } return(sivm.Symbol == sivm.Parent.SelectedStock.Symbol); }
/// <summary> /// Selects the template. /// </summary> /// <param name="item">The item.</param> /// <param name="container">The container.</param> /// <returns></returns> public override DataTemplate SelectTemplate(object item, DependencyObject container) { StockInfoViewModel vm = item as StockInfoViewModel; if (vm == null) { return(null); } switch (vm.Parent.SelectedChartType) { case 0: return(LineChartTemplate); case 1: return(OHLCChartTemplate); case 2: return(AreaChartTemplate); case 3: return(CandleStickTemplate); } return(null); }
public StockViewModel(IDialogService dialogService, StockInfoViewModel stockInfoViewModel) { _dialogService = dialogService; _stockInfoViewModel = stockInfoViewModel; }
/// <summary> /// Called when [series source changed]. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected virtual void OnSeriesSourceChanged(StockInfoViewModel oldValue, StockInfoViewModel newValue) { this.Series.Clear(); this.Axes.Clear(); if (newValue != null) { DataTemplate axisCategoryXTemplate = GetCurentAxisCategoryXTemplate(null); DataTemplate axisCategoryYTemplate = GetCurentAxisCategoryYTemplate(null); DataTemplate axisFinancialIndicatorYTemplate = GetCurentAxisFinancialIndicatorYTemplate(null); // X Axis if (axisCategoryXTemplate != null) { // load data template content var axisCategoryX = axisCategoryXTemplate.LoadContent() as Axis; if (axisCategoryX != null) { axisCategoryX.DataContext = SeriesSource; this.Axes.Add(axisCategoryX); } } // Y Axis if (axisCategoryYTemplate != null) { // load data template content var axisCategoryY = axisCategoryYTemplate.LoadContent() as Axis; if (axisCategoryY != null) { axisCategoryY.DataContext = DataContext; this.Axes.Add(axisCategoryY); } } //Financial Indicator Y Axis if (axisFinancialIndicatorYTemplate != null) { // load data template content var axisFinancialIndicatorY = axisFinancialIndicatorYTemplate.LoadContent() as Axis; if (axisFinancialIndicatorY != null) { axisFinancialIndicatorY.DataContext = DataContext; this.Axes.Add(axisFinancialIndicatorY); } } StockInfoViewModel item = newValue; DataTemplate dataTemplate = GetCurentSeriesTemplate(item); if (dataTemplate != null) { // load data template content var series = dataTemplate.LoadContent() as Series; var financialIndicator = FinancialIndicatorSeriesTemplate.LoadContent() as Series; if (series != null) { // set data context series.DataContext = item; financialIndicator.DataContext = item; this.Series.Add(series); series.RefreshXAxis <CategoryXAxis>(this); series.RefreshYAxis <NumericYAxis>(this); this.Series.Add(financialIndicator); financialIndicator.RefreshXAxis <CategoryXAxis>(this); financialIndicator.RefreshYAxis <NumericYAxis>(this); } } } // TODO Listen for INotifyCollectionChanged with a weak event pattern }