public bool SaveStockSymbol(StockSymbol symbol)
        {
            try
            {
                if (symbol == null)
                {
                    throw new ArgumentNullException("Symbol cannot be null");
                }
                if (string.IsNullOrWhiteSpace(symbol.Ticker) || symbol.Ticker.Length > 10)
                {
                    throw new ArgumentException("Ticker should be 1 to 10 character long");
                }

                Guid currentUserID = Guid.Parse(HttpContext.Current.User.Identity.GetUserId());
                symbol.UserID = currentUserID;

                _unitOfWork.StockSymbolRepository.Insert(symbol);
                _unitOfWork.Save();

                return(true);
            }
            catch (Exception ex)
            {
                _log.Create().WriteLog(LogType.HandledLog, this.GetType().Name, "SaveStockSymbol", ex, "Failed to add stock symbol");
            }
            return(false);
        }
Beispiel #2
0
        internal void LoadAPIKeys()
        {
            try
            {
                Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

                this.PublicKey  = config.AppSettings.Settings["PublicKey"].Value;
                this.PrivateKey = config.AppSettings.Settings["PrivateKey"].Value;
            }
            catch (Exception ex)
            {
                _log.Create().WriteLog(LogType.HandledLog, this.GetType().Name, "LoadAPIKeys", ex, "Failed to load api keys");
                UserSession.ActionResponseMessage = new ActionResponse("Failed to load api keys", ActionResponseMessageType.Error);
            }
        }
Beispiel #3
0
        internal object GetPricesJson(DataTablesAjaxRequestModel dataTablesModel)
        {
            try
            {
                Guid   currentUserID = Guid.Parse(HttpContext.Current.User.Identity.GetUserId());
                int    pageIndex     = dataTablesModel.GetPageIndex();
                int    pageSize      = dataTablesModel.GetPageSize();
                string sortOrder     = dataTablesModel.GetSortElements(new string[] { "ID",
                                                                                      "Ticker", "Price", "ID" });

                string searchText = dataTablesModel.GetSearchText();

                int totalRecords            = 0;
                int totalDisplayableRecords = 0;

                ICollection <StockSymbol> stockSymbols = new List <StockSymbol>();
                if (!string.IsNullOrWhiteSpace(searchText))
                {
                    stockSymbols = _unitOfWork.StockSymbolRepository.GetDynamic(out totalRecords, out totalDisplayableRecords,
                                                                                x => x.UserID == currentUserID && x.Ticker.Contains(searchText), sortOrder).ToList();
                }
                else
                {
                    stockSymbols = _unitOfWork.StockSymbolRepository.GetDynamic(out totalRecords, out totalDisplayableRecords,
                                                                                x => x.UserID == currentUserID, sortOrder).ToList();
                }

                totalRecords = _unitOfWork.StockSymbolRepository.GetCount(x => x.UserID == currentUserID);

                if (stockSymbols == null || stockSymbols.Count == 0)
                {
                    return(DataTablesAjaxRequestModel.EmptyResult);
                }

                ICollection <StockPrice> records = GetPriceFromAPI(stockSymbols);
                var jsonData = new
                {
                    iTotalRecords        = totalRecords,
                    iTotalDisplayRecords = totalDisplayableRecords,
                    aaData = (
                        from record in records
                        select new string[]
                    {
                        record.Symbol,
                        record.Price.ToString()
                    }
                        ).ToArray()
                };

                return(jsonData);
            }
            catch (Exception ex)
            {
                _log.Create().WriteLog(LogType.HandledLog, this.GetType().Name, "SaveStockSymbol", ex, "Failed to add stock symbol");

                UserSession.ActionResponseMessage = new ActionResponse("Failed to get symbol list", ActionResponseMessageType.Error);
            }
            return(DataTablesAjaxRequestModel.EmptyResult);
        }
 /// <summary>
 /// Createt a new <paramref name="Microsoft.Samples.NLayerApp.Infrastructure.Crosscutting.Logging.ILog"/>
 /// </summary>
 /// <returns>Created ILog</returns>
 public static ILogHelper CreateLog()
 {
     return((_currentLogFactory != null) ? _currentLogFactory.Create() : null);
 }