public JsonResult GridDataForStockPrices(DataTablesAjaxRequestModel dataTablesModel) { StockPriceViewModel model = new StockPriceViewModel(); var jsonData = model.GetPricesJson(dataTablesModel); return Json(jsonData, JsonRequestBehavior.AllowGet); }
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; }