public async Task <IActionResult> Index(Proposal proposal)
        {
            try
            {
                List <SuggestorB2b> plansList = await _telefonicaApi.GetSuggestedPlansByRut(proposal.RutCliente);

                var planMapped = _mapper.Map <List <SuggestorB2b>, List <SuggestorB2bModel> >(plansList);
                ViewData["suggestorLine"] = planMapped;
                return(View("../UserProposal/ProposalDetails", proposal));
            }
            catch (Exception ex)
            {
                var extraData = new { step = "ex", from = "UI" };
                var log       = new Log()
                {
                    Reference = "proDetailsIndex",
                    Messsage  = ex.Message,
                    ExtraData = extraData
                };

                var logged = await _telefonicaApi.InsertLog(log);

                ViewBag.ErrorMessage = "Error al cargar los detalles de la propuesta";
                return(View());
            }
        }
        public async Task <ActionResult> Login(string userName, string password)
        {
            try
            {
                if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
                {
                    bool isValid = true;
                    isValid = _telefonicaService.AuthenticationUser(userName, password);
                    var user = _telefonicaService.GetUserByUserName(userName);

                    if (isValid && user != null)
                    {
                        HttpContext.Session.SetString("LoggedUser", JsonConvert.SerializeObject(user));
                        HttpContext.Session.SetString("UserRole", user.RolString);

                        //seteo las cookies que no permiten ingresar a las demas funcionalidades si no esta logueado
                        SetLoginCookies(user.RolString);
                        await _telefonicaService.PopulateData();

                        return(RedirectToAction("Index", "Suggestor"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "El usuario o la constraseña son incorrectos";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "El usuario y la contraseña son mandatorios";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                var extraData = new { step = "ex", from = "UI" };
                var log       = new Log()
                {
                    Reference = "login",
                    Messsage  = ex.Message,
                    ExtraData = extraData
                };

                var logged = await _telefonicaService.InsertLog(log);

                if (logged)
                {
                    ViewBag.ErrorMessage = "Error al iniciar sesion";
                }
                else
                {
                    ViewBag.ErrorMessage = "-Error al iniciar sesion - Problemas en el log de errores";
                }

                return(View());
            }
        }
Exemplo n.º 3
0
        public bool AuthenticateUser(string userName, string password)
        {
            try
            {
                var               serviceLDAP       = _configuration.GetSection("ActiveDirectoryConfig").GetSection("servicioLDAP").Value;
                var               userPrefix        = _configuration.GetSection("ActiveDirectoryConfig").GetSection("UserPrefix").Value;
                var               directoryUserName = $@"{userPrefix}\{userPrefix}";
                DirectoryEntry    dE      = new DirectoryEntry(serviceLDAP, directoryUserName, password);
                DirectorySearcher dSearch = new DirectorySearcher(dE);
                SearchResult      results = null;
                results = dSearch.FindOne();

                var extraData = new { result = results };
                var log       = new Log()
                {
                    Reference = "AD",
                    Messsage  = "",
                    ExtraData = extraData
                };

                _telefonicaService.InsertLog(log);

                //string NTuserName = results.GetDirectoryEntry().Properties["SAMAccountName"].Value.ToString();
                //User usuarioLogueado = new User() { NombreCompleto = userName };

                if (results != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                var extraData = new { directory = "AD" };
                var log       = new Log()
                {
                    Reference = "AD",
                    Messsage  = ex.Message,
                    ExtraData = extraData
                };

                _telefonicaService.InsertLog(log);

                //return false;
                throw ex;
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var loggedUser = JsonConvert.DeserializeObject <TelefonicaModel.User>(HttpContext.Session.GetString("LoggedUser"));
                var userRole   = HttpContext.Session.GetString("UserRole");
                ViewData["loggedUser"] = loggedUser;
                ViewData["userRole"]   = userRole;
                var clientList = _telefonicaApi.GetCurrentClients();
                ViewData["clientList"] = clientList;
                var userList = await _telefonicaApi.GetUsers();

                ViewData["userList"] = userList;
                _telefonicaApi.SetCurrentProposal(null);
                if (userRole.Equals(Enum.GetName(typeof(Dto.Dto.UserRole), Dto.Dto.UserRole.Administrator)))
                {
                    var proposals = await _telefonicaApi.GetProposals();

                    return(View("../UserProposal/ProposalList", proposals));
                }
                else
                {
                    var proposals = await _telefonicaApi.GetProposalsByUser(loggedUser.Id.ToString());

                    return(View("../UserProposal/ProposalList", proposals));
                }
            }catch (Exception ex) {
                var extraData = new { step = "ex", from = "UI" };
                var log       = new Log()
                {
                    Reference = "UserIndex",
                    Messsage  = ex.Message,
                    ExtraData = extraData
                };

                await _telefonicaApi.InsertLog(log);

                var proposals = new List <Proposal>();
                ViewBag.ErrorMessage = "Error al cargar lista de propuestas";
                return(View("../UserProposal/ProposalList", proposals));
            }
        }
Exemplo n.º 5
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"));
            }
        }