Beispiel #1
0
        public async Task <IActionResult> Index(Brand brand)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
            {
                if (!ModelState.IsValid)
                {
                    return(NotFound());
                }
                if (_context.Brands.Any(b => b.Name == brand.Name))
                {
                    ModelState.AddModelError("Brand.Name", "Brand is already exsist");
                    LoadBrandsAdminVM vM = new LoadBrandsAdminVM {
                        Brands = _context.Brands.OrderBy(c => c.Name)
                    };
                    return(View(vM));
                }
                Brand newB = new Brand {
                    Name = brand.Name
                };
                await _context.Brands.AddAsync(newB);

                await _context.SaveChangesAsync();

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