Exemple #1
0
        public async Task <IActionResult> Index()
        {
            var loggedUser = JsonConvert.DeserializeObject <TelefonicaModel.User>(HttpContext.Session.GetString("LoggedUser"));

            if (loggedUser != null)
            {
                try
                {
                    _telefonicaApi.EmptyEquipoPymesCurrentList();
                    var clientList = _telefonicaApi.GetCurrentClients();
                    ViewData["loggedUser"] = loggedUser;
                    ViewData["userRole"]   = HttpContext.Session.GetString("UserRole");
                    var planesOfertList = _telefonicaApi.GetActualPlans();
                    ViewData["movileDevices"] = _telefonicaApi.GetEquiposPymesList();
                    ViewData["planOfertList"] = planesOfertList;
                    var planMapped = new List <SuggestorB2bModel>();
                    if (clientList != null && clientList.Count > 0)
                    {
                        ViewData["clientList"] = clientList;
                        List <SuggestorB2b> plansList = await _telefonicaApi.GetSuggestedPlansByRut(clientList[0].Documento);

                        planMapped = _mapper.Map <List <SuggestorB2b>, List <SuggestorB2bModel> >(plansList);
                        _telefonicaApi.UpdateCurrentClient(clientList[0].Documento);
                        var indexes = _telefonicaApi.CalculateIndexes();
                        ViewData["Indexes"] = indexes;
                    }
                    ViewData["planDefList"]   = _telefonicaApi.GetCurrentDefinitivePlans();
                    ViewData["mobileList"]    = new List <DevicePymesModel>();
                    ViewData["devicePayment"] = 0;
                    ViewData["subsidy"]       = 0;
                    ViewData["payback"]       = 0;
                    ViewData["currentClient"] = "null";
                    _telefonicaApi.SetCurrentProposal(null);

                    return(View("../Home/Suggestor", planMapped));
                }
                catch (Exception ex) {
                    var extraData = new { step = "ex", from = "UI" };
                    var log       = new Log()
                    {
                        Reference = "suggestorIndex",
                        Messsage  = ex.Message,
                        ExtraData = extraData
                    };

                    await _telefonicaApi.InsertLog(log);

                    ViewBag.ErrorMessage = "Error al cargar los elemenos";
                    var planMapped = new List <SuggestorB2bModel>();
                    return(View("../Home/Suggestor", planMapped));
                }
            }
            else
            {
                ViewBag.ErrorMessage = "No se encuentra logueado";
                return(View("../Login/Login"));
            }
        }