public ActionResult EditPais(PaisViewModel model)
        {
            if (User == null || User.GetType().ToString() == "System.Security.Principal.GenericPrincipal")
                return RedirectToAction("Index", "Home");

            if (!ModelState.IsValid)
            {
                ViewBag.Title = Resources.TablasResource.EditPaisPageTitle;
                ViewBag.PageHeader = Resources.TablasResource.EditPaisHeaderPage;
                return View(model);
            }

            using (SeguricelEntities db = new SeguricelEntities())
            {
                Pais regPais = (db.Pais.Where(x => x.IdPais == model.Id).FirstOrDefault());
                regPais.Nombre = model.Nombre;
                regPais.Activo = model.Activo;
                regPais.Culture = model.Culture;
                regPais.Ubicacion = DbGeography.FromText(string.Format("POINT({0} {1})", model.Longitud, model.Latitud));
                db.SaveChanges();

                ClasesVarias.AddBitacoraUsuario(db,
                   "País " + model.Nombre + " en condición de " + (model.Activo ? "Activo" : "Inactivo"),
                   190000003,
                   "Editar");

            }
            return RedirectToAction("Pais");
        }
        public ActionResult CreatePais(PaisViewModel model)
        {
            if (User == null || User.GetType().ToString() == "System.Security.Principal.GenericPrincipal")
                return RedirectToAction("Index", "Home");

            ViewBag.Title = Resources.TablasResource.CreatePaisPageTitle;
            ViewBag.PageHeader = Resources.TablasResource.CreatePaisHeaderPage;

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            try {
                using (SeguricelEntities db = new SeguricelEntities())
                {
                    Pais Pais = new Pais
                    {
                        IdPais = model.Id,
                        Activo = model.Activo,
                        Nombre = model.Nombre,
                        Culture = model.Culture,
                        Ubicacion = DbGeography.FromText(string.Format("POINT({0} {1})", model.Longitud, model.Latitud))
                    };

                    db.Pais.Add(Pais);
                    db.SaveChanges();

                    ClasesVarias.AddBitacoraUsuario(db,
                       "País " + model.Nombre + " en condición de " + (model.Activo ? "Activo" : "Inactivo"),
                       190000003,
                       "Agregar");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return RedirectToAction("Pais");

        }
        public ActionResult EditPais(int? Id)
        {
            if (User == null || User.GetType().ToString() == "System.Security.Principal.GenericPrincipal" || Id == null)
                return RedirectToAction("Index", "Home");

            ViewBag.Title = Resources.TablasResource.EditPaisPageTitle;
            ViewBag.PageHeader = Resources.TablasResource.EditPaisHeaderPage;
            PaisViewModel model = new PaisViewModel();

            using (SeguricelEntities db = new SeguricelEntities())
            {
                model = (db.Pais.Where(x => x.IdPais == Id)
                            .Select(x => new PaisViewModel
                            {
                                Activo = x.Activo,
                                Id = x.IdPais,
                                Nombre = x.Nombre,
                                Culture = x.Culture,
                                Latitud = x.Ubicacion.Latitude.ToString(),
                                Longitud = x.Ubicacion.Longitude.ToString()
                            }).FirstOrDefault());
            }

            return View(model);
        }
        public ActionResult CreatePais()
        {
            if (User == null || User.GetType().ToString() == "System.Security.Principal.GenericPrincipal")
                return RedirectToAction("Index", "Home");

            Nullable<int> NextId = null;

            ViewBag.Title = Resources.TablasResource.CreatePaisPageTitle;
            ViewBag.PageHeader = Resources.TablasResource.CreatePaisHeaderPage;
            PaisViewModel model = new PaisViewModel();
            model.Longitud = User.Longitd.ToString();
            model.Latitud = User.Latitud.ToString();

            using (SeguricelEntities db = new SeguricelEntities())
            {
                NextId = (db.Pais.Select(x => (int?)x.IdPais).Max() ?? 0);
            }

            if (NextId == null)
                NextId = 0;

            NextId += 1;

            model.Id = (int)NextId;

            return View(model);
        }