//public ActionResult Search(string search, int? i) //{ // if (search != null) // { // BrandsCategoriesViewModel bcvm = new BrandsCategoriesViewModel(); // bcvm.categories = ctx.Categories.ToList(); // bcvm.brands = ctx.Brands.ToList(); // bcvm.products = ctx.Products.Where(p => p.Name.Contains(search)).ToList().ToPagedList(i ?? 1, 10); // ViewBag.title = search; // ViewBag.count = bcvm.products.Count(); // return View("Products_Listing", bcvm); // } // else{ // return RedirectToAction("Products_Listing"); // } //} public ActionResult Products_Listing(string search, int?id, int?i) { BrandsCategoriesViewModel bcvm = new BrandsCategoriesViewModel(); bcvm.categories = ctx.Categories.ToList(); bcvm.brands = ctx.Brands.ToList(); if (search != null) { bcvm.products = ctx.Products.Where(p => p.Name.Contains(search)).ToList().ToPagedList(i ?? 1, 10); ViewBag.title = search; ViewBag.count = bcvm.products.Count(); } else { if (id != null) { bcvm.products = ctx.Products.Where(p => p.FK_CategoryId == id).ToList().ToPagedList(i ?? 1, 10); ViewBag.title = ctx.Categories.Find(id).Name; } else { bcvm.products = ctx.Products.ToList().ToPagedList(i ?? 1, 10); ViewBag.title = "All Products"; } } ViewBag.count = bcvm.products.Count(); return(View(bcvm)); }
public ActionResult Index() { BrandsCategoriesViewModel bcvm = new BrandsCategoriesViewModel() { categories = ctx.Categories.ToList(), brands = ctx.Brands.ToList() }; IdentityRole admin = new IdentityRole("Admin"); IdentityRole user = new IdentityRole("User"); IdentityRole seller = new IdentityRole("Seller"); //creates object of role manager which has the create role function RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext())); roleManager.Create(admin); roleManager.Create(user); roleManager.Create(seller); //assign views to roles UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); //ApplicationUser adminUser = userManager.FindByEmail("*****@*****.**"); //ApplicationUser userUser = userManager.FindByEmail("*****@*****.**"); //ApplicationUser sellerUser = userManager.FindByEmail("*****@*****.**"); //userManager.AddToRole(adminUser.Id, "Admin"); //adminUser.RoleName = "Admin"; //userManager.AddToRole(userUser.Id, "User"); //adminUser.RoleName = "User"; //userManager.AddToRole(sellerUser.Id, "Seller"); //adminUser.RoleName = "Seller"; return(View(bcvm)); }
public ActionResult Products_Listing_Brand(int?id, int?i) { BrandsCategoriesViewModel bcvm = new BrandsCategoriesViewModel(); bcvm.categories = ctx.Categories.ToList(); bcvm.brands = ctx.Brands.ToList(); if (id != null) { ViewBag.brand = true; bcvm.products = ctx.Products.Where(p => p.FK_BrandId == id).ToList().ToPagedList(i ?? 1, 10); ViewBag.title = ctx.Brands.Find(id).Name; } else { bcvm.products = ctx.Products.ToList().ToPagedList(i ?? 1, 10); ViewBag.title = "All Products"; } ViewBag.count = bcvm.products.Count(); return(View("Products_Listing", bcvm)); }