public PartialViewResult Seach(int page, string name, decimal price, int quantity, long categoryId) { try { var query = from x in con.Products where x.IsActive == 1 select x; if (name != null) { if (name.Trim() != "") { query = query.Where(u => u.Name.Contains(name)); } } if (price != 0) { query = query.Where(u => u.Price <= price); } if (quantity != 0) { query = query.Where(u => u.Quantity <= quantity); } if (categoryId != 0) { query = query.Where(u => u.CategoryID == categoryId); } if (query != null && query.Count() > 0) { List <GetProductModels> listProduct = new List <GetProductModels>(); foreach (Product us in query) { GetProductModels productModels = new GetProductModels(); productModels.Name = us.Name; productModels.Price = us.Price; productModels.Quantity = us.Quantity; productModels.CategoryID = us.CategoryID; ProductCategory productCategory = con.ProductCategories.Find(us.CategoryID); if (productCategory != null) { productModels.Name = productCategory.Name; } listProduct.Add(productModels); } return(PartialView("_List", listProduct.ToPagedList(page, Constants.MAX_ROW_IN_LIST))); } else { return(PartialView("_List", new List <GetProductModels>().ToPagedList(1, 1))); } } catch (Exception ex) { throw ex; } }
public JsonResult GetProductById(long Id) { try { var query = con.Products.Find(Id); if (query != null) { GetProductModels productModels = new GetProductModels() { ID = query.ID, Name = query.Name, MetaTitle = query.MetaTitle, Description = query.Description, Image = query.Image, AltImage = query.AltImage, MoreImages = query.MoreImages, Price = query.Price, Percent = query.Percent, PromotionPrice = query.PromotionPrice, Quantity = query.Quantity, CategoryID = query.CategoryID, // CategoryName = query.ca DescriptionIdDetail = query.DescriptionIdDetail, Warranty = query.Warranty, CreatedDate = query.CreatedDate, CreatedBy = query.CreatedBy, ModifiedDate = query.ModifiedDate, ModifiedBy = query.ModifiedBy, MetaKeywords = query.MetaKeywords, MetaDescriptions = query.MetaDescriptions, Status = query.Status, TopHot = query.TopHot, Sale = query.Sale, ViewCount = query.ViewCount, IsActive = query.IsActive }; return(Json(productModels, JsonRequestBehavior.AllowGet)); } else { return(Json(new GetProductModels(), JsonRequestBehavior.AllowGet)); } } catch { return(Json(new GetProductModels(), JsonRequestBehavior.AllowGet)); } }