public async Task <IActionResult> Detail(string urlSubgroup = null, string name = null, string color = null) { IEnumerable <ProductDetails> result; var pro = productBLL.SearchByUrl(name); if (pro == null) { return(NotFound()); } var spe = pro.Specification; result = await productDetailsBLL.Get(filter : p => p.ProductID == pro.ID); string Color = null; if (color != null) { Color = color; result = result.Where(p => p.TypeColor.ToString() == color); } else if (result.Count() > 0) { var firstProductDetails = result.FirstOrDefault(); Color = firstProductDetails.TypeColor.ToString(); result = result.Where(p => p.TypeColor == firstProductDetails.TypeColor).ToList(); } decimal price = pro.Price; //string IDtemp = id; List <string> listSize = new List <string>(); List <string> listColor = new List <string>(); List <string> listIdDetail = new List <string>(); string listImage = null; if (result.Count() > 0) { foreach (var i in result) { if (listColor.FirstOrDefault(p => p == i.TypeColor.ToString()) == null) { listColor.Add(i.TypeColor.ToString()); } } var selectedColor = result.FirstOrDefault().TypeColor; result = result.Where(p => p.TypeColor == selectedColor).ToList(); foreach (var i in result) { listImage = listImage + "," + i.listImages; price = i.Price; listSize.Add(i.Size.ToString()); listIdDetail.Add(i.ID); } } LoadDetailsViewModel temp = new LoadDetailsViewModel() { ListIDDetails = listIdDetail, ListSize = listSize, ID = pro.ID, Color = Color, DefaultImages = pro.DefaultImage, Model = pro.Model, ListImage = listImage, ListColor = listColor, Price = price == 0 ? "Chưa có hàng" : price.ToString(), Descrtiption = pro.Details, Specification = pro.Specification, IsAllowFacebookComment = pro.IsAllowComment, Quantity = 0, CurrentSize = "chua co", ImagePath = pro.DefaultImage }; ViewBag.Title = pro.MetaTitle; if (color != null) { ViewBag.Name = pro.Model + "-" + color; } else { ViewBag.Name = pro.Model; } ViewBag.Keyword = pro.MetaDescription; ViewBag.Description = pro.MetaDescription; ViewBag.Image = pro.DefaultImage; return(View("~/Views/Shop/Detail.cshtml", temp)); }