public JsonResult GetListRelateProduct(int id) { IRepositryBase <Fly_Product> repository = new ProductDAO(); IRepositryRelateProducts <Fly_RelatedProduct> _repoRelatedProduct = new RelatedProductDAO(); try { List <Fly_RelatedProduct> listRelate = _repoRelatedProduct.getAllItemsByProductID(id).ToList(); List <Fly_Product> listProduct = new List <Fly_Product>(); foreach (var item in listRelate) { listProduct.Add(repository.getItem(item.ProductID2.GetValueOrDefault())); } var rs = from i in listRelate join a in listProduct on i.ProductID2 equals a.ProductId select new { i.RelatedProductID, a.Name, i.ProductID1, i.ProductID2, a.Fly_ProductPicture.Where(y => y.ProductID == a.ProductId).FirstOrDefault().Fly_Picture.OriginalURL }; return(Json(rs, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(e.Message)); } }
public JsonResult RemoveRelateProduct(int id) { IRepositryRelateProducts <Fly_RelatedProduct> repoRelatedProduct = new RelatedProductDAO(); bool result = false; try { repoRelatedProduct.Delete(id); result = true; } catch (Exception) { result = false; } return(Json(new { result = result })); }