Example #1
0
        public ActionResult DetallesEmpresa(string nombre)
        {
            var model = service.GetEmpresaByNombre(nombre);

            if (model != null)
            {
                StringFactory.SetStringEmpresas(model.Bd);
                Session.Session.SetIdEmpresa(HttpContext.Session, (int)model.Id);
                try
                {
                    using (SqlConnection conn = new SqlConnection(StringFactory.StringEmpresas))
                    {
                        conn.Open();
                        conn.Close();
                        HttpContext.Session.SetString("empresa", "The Doctor");
                        HttpContext.Session.SetInt32("idEmpresa", (int)model.Id);
                        return(View(model));
                    }
                }
                catch
                {
                    return(RedirectToAction("ListarEmpresas"));
                }
            }
            else
            {
                return(RedirectToAction("ListarEmpresas"));
            }
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjectionConfig.AddScope(services);

            //se agrega el context con un string base en appsettings

            StringFactory.SetStringEmpresas(Configuration.GetConnectionString("EmpresasString"));

            services.AddDbContext <EmpresasContext>(options =>
                                                    options.UseSqlServer(StringFactory.StringEmpresas));

            StringFactory.SetStringGE(Configuration.GetConnectionString("GrupoEmpresarialString"));

            services.AddDbContext <GrupoEmpresarialContext>(options =>
                                                            options.UseSqlServer(StringFactory.StringGE));

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath        = "/Cuenta/Login/";
                options.AccessDeniedPath = "/Cuenta/Login/";
            });

            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");

            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                //options.IdleTimeout = TimeSpan.FromMinutes(30);
                options.Cookie.HttpOnly = true;
                // Make the session cookie essential
                options.Cookie.IsEssential = true;
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.Configure <IISServerOptions>(options =>
            {
                options.AutomaticAuthentication = false;
            });
        }
        public ActionResult DetallesEmpresa(string nombre, string contexto = "")
        {
            var model = service.GetEmpresaByNombre(nombre);

            if (model != null)
            {
                StringFactory.SetStringEmpresas(HttpContext.Session, model.Bd);
                Sesion.Sesion.SetIdEmpresa(HttpContext.Session, (int)model.Id);
                Sesion.Sesion.SetFotoEmpresa(HttpContext.Session, model.Foto);
                Sesion.Sesion.SetNombreEmpresa(HttpContext.Session, model.Nombre);
                try
                {
                    using (SqlConnection conn = new SqlConnection(StringFactory.StringEmpresas))
                    {
                        conn.Open();
                        conn.Close();
                        HttpContext.Session.SetInt32("idEmpresa", (int)model.Id);

                        if (contexto != "")
                        {
                            return(RedirectToAction("Index", "AccesoRapido"));
                        }
                        else
                        {
                            return(View(model));
                        }
                    }
                }
                catch (Exception ex)
                {
                    AltivaLog.Log.Insertar(ex.ToString(), "Error");
                    return(RedirectToAction("ListarEmpresas"));
                }
            }
            else
            {
                return(RedirectToAction("ListarEmpresas"));
            }
        }