Ejemplo n.º 1
0
        public async Task <IActionResult> Index(Country country)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
            {
                if (!ModelState.IsValid)
                {
                    return(PartialView("ErrorPage"));
                }
                if (_context.Countries.Any(c => c.Name == country.Name))
                {
                    LoadCountriesAdminVM vM = new LoadCountriesAdminVM {
                        Countries = _context.Countries.OrderBy(c => c.Name)
                    };
                    ModelState.AddModelError("Country.Name", "Country is already exsist");
                    return(View(vM));
                }
                Country newC = new Country {
                    Name = country.Name
                };
                await _context.Countries.AddAsync(newC);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.IsHeaderNonVisible = true;
            return(Redirect("/account/login"));
        }
Ejemplo n.º 2
0
 public IActionResult Index()
 {
     if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
     {
         LoadCountriesAdminVM vM = new LoadCountriesAdminVM {
             Countries = _context.Countries.OrderBy(c => c.Name).Take(10)
         };
         ViewBag.Countries = _context.Countries.Count();
         return(View(vM));
     }
     ViewBag.IsHeaderNonVisible = true;
     return(Redirect("/account/login"));
 }