public IActionResult Swing()
        {
            NSEInsiderResponse resp = new NSEInsiderResponse();

            if (TempData["Cookie"].IsNotNull())
            {
                resp.Cookie = Convert.ToString(TempData["Cookie"]);
            }
            resp.IsCookieRequired = true;
            return(View(resp));
        }
 public IActionResult SwingValue(NSEInsiderResponse request)
 {
     try
     {
         if (request.IsNull() || !request.Symbols.HasRecords() || request.Cookie.IsNull())
         {
             return(View(new NSEInsiderResponse()
             {
                 ErrorMessage = CommonError.InvalidRequest
             }));
         }
         TempData["Cookie"]  = request.Cookie;
         TempData["Symbols"] = request.Symbols;
         List <StockData> stocks  = new List <StockData>();
         List <string>    symbols = request.Symbols.Split(',').ToList();
         foreach (var symbol in symbols)
         {
             var price = GetAveragePrice(symbol, request.Cookie);
             if (price == -1)
             {
                 break;
             }
             else
             {
                 stocks.Add(new StockData()
                 {
                     Symbol = symbol, AveragePrice = price
                 });
             }
         }
         if (!stocks.HasRecords())
         {
             return(View(new NSEInsiderResponse()
             {
                 IsCookieRequired = true, ErrorMessage = CommonError.CookieExpired
             }));
         }
         return(View(new NSEInsiderResponse()
         {
             IsSuccess = true, Stocks = stocks, Cookie = request.Cookie
         }));
     }
     catch (Exception)
     {
         return(View(new NSEInsiderResponse()
         {
             IsCookieRequired = true, ErrorMessage = CommonError.CookieExpired
         }));
     }
 }
        public IActionResult SwingValue()
        {
            NSEInsiderResponse resp = new NSEInsiderResponse();

            if (TempData["Symbols"].IsNotNull())
            {
                resp.Symbols = Convert.ToString(TempData["Symbols"]);
            }
            if (TempData["Cookie"].IsNotNull())
            {
                resp.Cookie = Convert.ToString(TempData["Cookie"]);
            }
            return(View(resp));
        }
 public IActionResult Swing(NSEInsiderResponse request)
 {
     try
     {
         NSEInsider response = RestServiceUtils.MakeGetRestCallByTimeOut <NSEInsider>(URLConstants.NSEInsiderAPI, "https://www.nseindia.com/", 2, request.Cookie);
         if (response.IsNull())
         {
             return(View(new NSEInsiderResponse()
             {
                 ErrorMessage = CommonError.FailedToFetchData
             }));
         }
         if (!response.data.HasRecords())
         {
             return(View(new NSEInsiderResponse()
             {
                 ErrorMessage = CommonError.FailedToFetchData
             }));
         }
         List <StockData> filteredData = response.data.Where(x => x.acqMode == "Market Purchase" && (x.personCategory == "Promoter Group" || x.personCategory == "Promoters"))
                                         .GroupBy(r => r.symbol)
                                         .Select(a => new StockData()
         {
             Symbol = a.Key, Value = a.Sum(b => long.Parse(b.secVal))
         })
                                         .Where(p => p.Value > long.Parse("10000000")).OrderByDescending(x => x.Value)
                                         .ToList();
         TempData["Cookie"]  = request.Cookie;
         TempData["Symbols"] = string.Join(",", filteredData.Select(x => x.Symbol).ToList());
         if (filteredData.HasRecords())
         {
             return(View(new NSEInsiderResponse()
             {
                 IsSuccess = true, Stocks = filteredData, Cookie = request.Cookie, Symbols = string.Join(",", filteredData.Select(x => x.Symbol).ToList())
             }));
         }
         return(View(new NSEInsiderResponse()
         {
             ErrorMessage = CommonError.NoRecordsFound
         }));
     }
     catch (Exception)
     {
         return(View(new NSEInsiderResponse()
         {
             IsCookieRequired = true, ErrorMessage = CommonError.CookieExpired
         }));
     }
 }
        public IActionResult CorporateInfo()
        {
            NSEInsiderResponse response = new NSEInsiderResponse();

            try
            {
                string allSymbols = default(string);
                if (TempData["Symbols"].IsNotNull())
                {
                    allSymbols = Convert.ToString(TempData["Symbols"]);
                }
                if (TempData["Cookie"].IsNotNull())
                {
                    response.Cookie = Convert.ToString(TempData["Cookie"]);
                }
                if (string.IsNullOrEmpty(allSymbols) || string.IsNullOrEmpty(response.Cookie))
                {
                    response.ErrorMessage = "Invalid Request/Cookie Expired!";
                    return(View("Swing", response));
                }
                List <string>    Allsymbols     = allSymbols.Split(',').ToList();
                List <StockData> filteredStocks = new List <StockData>();
                foreach (var symbol in Allsymbols)
                {
                    var priceTask = Task.Factory.StartNew(() => GetAveragePrice(symbol, response.Cookie));
                    var resp      = GetCorpInfo(symbol, response.Cookie);
                    priceTask.Wait();
                    if (resp.IsNotNull())
                    {
                        filteredStocks.Add(new StockData()
                        {
                            Symbol = symbol, PromoterInfo = resp.PromoterDetails.Split("Promoter & Promoter Group,")[1].Split('}')[0], AveragePrice = priceTask.Result
                        });
                    }
                }
                if (filteredStocks.HasRecords())
                {
                    response.IsEligibleResponse = true;
                    response.Stocks             = filteredStocks;
                }
                return(View("Swing", response));
            }
            catch (Exception)
            {
                response.IsCookieRequired = true;
                response.ErrorMessage     = CommonError.CookieExpired;
                return(View("Swing", response));
            }
        }