public async Task <IActionResult> Index()
        {
            try
            {
                if (HttpContext.Session.GetString("token") == null)
                {
                    _log.Info("token not found");
                    return(RedirectToAction("Login", "User"));
                }
                else
                {
                    _log.Info("Displaying Schedule input page");
                    _token    = HttpContext.Session.GetString("token");
                    _response = await _demandProvider.GetStock(_token);

                    if (_response.IsSuccessStatusCode)
                    {
                        _log.Info("stock received");
                        var result = await _response.Content.ReadAsStringAsync();

                        List <MedicineStock>  stocks  = JsonConvert.DeserializeObject <List <MedicineStock> >(result);
                        List <MedicineDemand> demands = _demandProvider.GetDemand(stocks);
                        return(View(demands));
                    }
                    else if (_response.StatusCode == HttpStatusCode.NotFound)
                    {
                        _log.Error("error while getting stock");
                        return(View("NoStock"));
                    }
                    else if (_response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        return(View("Unauthorized"));
                    }
                    else
                    {
                        return(View("Error"));
                    }
                }
            }
            catch (Exception e)
            {
                _log.Info("Error in DemandController while displaying input page for user : "******"userName") + " - " + e.Message);
                return(View("Error"));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Index()
        {
            try
            {
                if (HttpContext.Session.GetString("token") == null)
                {
                    return(RedirectToAction("Login", "User"));
                }
                else
                {
                    _response = await _demandProvider.GetStock();

                    if (_response.IsSuccessStatusCode)
                    {
                        var result = await _response.Content.ReadAsStringAsync();

                        List <MedicineStock>  stocks  = JsonConvert.DeserializeObject <List <MedicineStock> >(result);
                        List <MedicineDemand> demands = _demandProvider.GetDemand(stocks);
                        return(View(demands));
                    }
                    else if (_response.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(View("NoSupply"));
                    }
                    else if (_response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        return(View("Unauthorized"));
                    }
                    else
                    {
                        return(View("Error"));
                    }
                }
            }
            catch (Exception)
            {
                return(View("Error"));
            }
        }