public ActionResult ProductAndListings(string id) { Product product = db.Products.FirstOrDefault(x => x.ProductId == id); List <Listing> listings = db.Listings.Where(x => x.ProductId == id).ToList(); listingViewModels = new List <ListingViewModel>(); for (int i = 0; i < listings.Count; i++) { ListingViewModel lo = new ListingViewModel(); lo.Listing = listings.ElementAt(i); string listingId = lo.Listing.ListingId; string sellerId = listings.ElementAt(i).SellerId; lo.Offers = db.Offers.Where(x => x.ListingId == lo.Listing.ListingId).ToList(); Seller seller = db.Sellers.Where(x => x.SellerId == sellerId).First(); lo.Product = product; lo.Seller = seller; //lo.ProcessingOption = db listingViewModels.Add(lo); } List <string> tags = new List <string>(); ProductAndListingsModel pm = new ProductAndListingsModel(); pm.ProductTags = new List <Tag>(); pm.ListingViewModels = listingViewModels; pm.TagCategories = db.TagCategories.ToList(); string productId = product.ProductId; List <TagAssociation> associations = db.TagAssociations.Where(x => x.ProductId.Contains(productId)).ToList(); foreach (var item in associations) { if (!tags.Contains(item.TagId)) { tags.Add(item.TagId); string tagId = item.TagId; Tag t = db.Tags.Where(x => x.TagId.Contains(tagId)).First(); pm.ProductTags.Add(t); } } ListingTagCategory category = db.ListingTagCategories.Where(x => x.Name.Contains("Processing Options")).FirstOrDefault(); string processingOptionsTagCategory = category.ListingTagCategoryId.Trim(); pm.processingOptions = db.ListingTags.Where(x => x.ListingTagCategoryId.Contains(processingOptionsTagCategory)).ToList(); pm.Product = product; return(View(pm)); }
public ActionResult ProductAndListings(string productId) { Product product = db.Products.FirstOrDefault(x => x.ProductId == productId); List <Listing> listings = db.Listings.Where(x => x.ProductId == productId).ToList(); listingViewModels = new List <ListingViewModel>(); for (int i = 0; i < listings.Count; i++) { ListingViewModel lo = new ListingViewModel(); lo.Listing = listings.ElementAt(i); string sellerId = listings.ElementAt(i).SellerId; Seller seller = db.Sellers.Where(x => x.SellerId == sellerId).First(); lo.UnitPriceKG = lo.Listing.UnitPriceKG; lo.UnitsKG = lo.Listing.UnitsKG; lo.Product = product; lo.Seller = seller; listingViewModels.Add(lo); } ProductAndListingsModel pm = new ProductAndListingsModel(); pm.ListingViewModels = listingViewModels; pm.Product = product; return(View(pm)); }