public ActionResult Index(int?brand, int?model) { JivivContext context = new JivivContext(); var models = context.Models.Where(x => x.BrandId == brand).ToList(); var brands = context.Brands.ToList(); ViewBag.Brands = new SelectList(brands, "Id", "Name"); ViewBag.Models = new SelectList(models, "Id", "Name"); var detail = new DetailSaleInformation(); var lstBrands = new List <Brand>(); var lstModels = new List <CarModel>(); var lstUsers = new List <User>(); var sales = context.Sales.Where(x => x.BrandId == brand && x.ModelId == model).ToList(); foreach (var item in sales) { lstBrands.Add(context.Brands.Find(item.BrandId)); lstModels.Add(context.Models.Find(item.ModelId)); lstUsers.Add(context.Users.Find(item.UserId)); } detail.Brands = lstBrands; detail.Models = lstModels; detail.Users = lstUsers; detail.Sales = sales; return(View(detail)); }
public ActionResult UserProfile(int id) { var detail = new DetailSaleInformation(); var lstBrands = new List <Brand>(); var lstModels = new List <CarModel>(); JivivContext context = new JivivContext(); var sales = context.Sales.Where(x => x.UserId == id).ToList(); foreach (var item in sales) { lstBrands.Add(context.Brands.Find(item.BrandId)); lstModels.Add(context.Models.Find(item.ModelId)); } detail.Brands = lstBrands; detail.Models = lstModels; detail.Sales = sales; return(View(detail)); }