public JsonResult GetContentById(long Id) { try { var query = con.Contents.Find(Id); if (query != null) { GetContentModels contentModels = new GetContentModels() { ID = query.ID, Name = query.Name, MetaTitle = query.MetaTitle, Description = query.Description, Image = query.Image, AltImage = query.AltImage, MoreImages = query.MoreImages, CategoryID = (long)query.CategoryID, DescriptionIdDetail = query.DescriptionIdDetail, Warranty = (int)query.Warranty, CreatedDate = (DateTime)query.CreatedDate, CreatedBy = query.CreatedBy, ModifiedDate = (DateTime)query.ModifiedDate, ModifiedBy = query.ModifiedBy, MetaKeywords = query.MetaKeywords, MetaDescriptions = query.MetaDescriptions, Status = (bool)query.Status, TopHot = (int)query.TopHot, ViewCount = (int)query.ViewCount, IsActive = (int)query.IsActive, Tag = query.Tag }; return(Json(contentModels, JsonRequestBehavior.AllowGet)); } else { return(Json(new GetContentModels(), JsonRequestBehavior.AllowGet)); } } catch { return(Json(new GetContentModels(), JsonRequestBehavior.AllowGet)); } }
public PartialViewResult Seach(int Page, string Name, long CategoryId, int topHot, int GroupCategory = 0) { try { var query = from x in con.Contents where x.IsActive == 1 select x; if (Name != null) { if (Name.Trim() != "") { query = query.Where(u => u.Name.Contains(Name)); } } if (CategoryId != 0) { query = query.Where(x => x.CategoryID == CategoryId); } if (topHot != 0) { query = query.Where(x => x.TopHot == topHot); } if (GroupCategory != 0) { query = query.Where(u => u.CategoryID == GroupCategory); } if (query != null && query.Count() > 0) { List <GetContentModels> listContent = new List <GetContentModels>(); foreach (Content us in query) { GetContentModels contentModels = new GetContentModels(); contentModels.Name = us.Name; contentModels.Image = us.Image; contentModels.AltImage = us.AltImage; contentModels.MoreImages = us.MoreImages; contentModels.CategoryID = us.CategoryID; contentModels.Warranty = us.Warranty; contentModels.TopHot = us.TopHot; contentModels.ViewCount = us.ViewCount; contentModels.IsActive = us.IsActive; Category categoryGroup = con.Categories.Find(us.CategoryID); if (categoryGroup != null) { contentModels.CategoryName = categoryGroup.Name; } listContent.Add(contentModels); } return(PartialView("_List", listContent.ToPagedList(Page, Constants.MAX_ROW_IN_LIST))); } else { return(PartialView("_List", new List <GetContentModels>().ToPagedList(1, 1))); } } catch (Exception ex) { throw ex; } }