// GET: Project public ActionResult Index(string catagory, int currentPage) { ProjectViewModel viewModel = new ProjectViewModel(); viewModel.Catagorys = new List<InfoCatagory>(); var q = from d in dbContext.Projects group d by d.CatagoryProject.CatagoryProjectName into counts select new { Count = counts.Count(), Group = counts.Key }; foreach (var item in q) { InfoCatagory project = new InfoCatagory { Name = item.Group.ToString()}; viewModel.Catagorys.Add(project); } viewModel.Catagorys.Insert(0, new InfoCatagory { Name = "All"}); if (catagory == "All") { viewModel.Projects = dbContext.Projects.OrderBy(x => x.Name).Skip((currentPage - 1) * itemsPage).Take(itemsPage).ToList(); viewModel.PageNumbers = (int)Math.Ceiling((decimal)dbContext.Projects.Count() / (decimal)itemsPage); } else { viewModel.Projects = dbContext.Projects.Where(x => x.CatagoryProject.CatagoryProjectName == catagory).OrderBy(x => x.Name).Skip((currentPage - 1) * itemsPage).Take(itemsPage).ToList(); viewModel.PageNumbers = (int)Math.Ceiling((decimal)dbContext.Projects.Where(x => x.CatagoryProject.CatagoryProjectName == catagory).Count() / (decimal)itemsPage); } viewModel.CurrentPage = currentPage; return View(viewModel); }
// GET: Solution public ActionResult Index(string catagory = "Tất cả", string subCatagory = null) { if (subCatagory != null) { subCatagory = subCatagory.Replace("_", " ").Replace("-", "&"); } catagory = catagory.Replace("_", " ").Replace("-", "&"); SolutionViewModel viewModel = new SolutionViewModel(); viewModel.InfoCatagorys = new List<InfoCatagory>(); var q = from d in dbContext.Solutions group d by d.SubCatagorySolutionId into counts select new { Count = counts.Count(), Group = dbContext.SubCatagorySolutions.Where(x => x.SubCatagorySolutionId == counts.Key).Select(y => y.SubCatagorySolutionName).FirstOrDefault().ToString(), Belong = dbContext.SubCatagorySolutions.Where(y => y.SubCatagorySolutionId == counts.Key).Select(z => z.CatagorySolution.CatagorySolutionName).FirstOrDefault().ToString() }; List<InfoCatagory> infoCatagorys = new List<InfoCatagory>(); var p = from i in q group i by i.Belong into lists select new { Count = lists.Count(), Group = lists.Key }; foreach (var item in p) { InfoCatagory info = new InfoCatagory { Name = item.Group.ToString() }; infoCatagorys.Add(info); } foreach (var item in q) { foreach (var i in infoCatagorys) { if (i.Name == item.Belong) { if (i.InfoSubCatagorys == null) { i.InfoSubCatagorys = new List<string>(); i.InfoSubCatagorys.Add(item.Group); } else { i.InfoSubCatagorys.Add(item.Group); } } } //infoCatagory.InfoSubCatagorys.Add(infoSubCata); } infoCatagorys.Insert(0, new InfoCatagory { Name = "Tất cả" }); viewModel.InfoCatagorys = infoCatagorys; //viewModel.InfoCatagorys.Insert(0, new InfoCatagory { Name = "All", Count = dbContext.Products.Count() }); viewModel.Solutions = dbContext.Solutions.Include(x => x.SubCatagorySolution.CatagorySolution).OrderBy(x => x.Name).ToList(); return View(viewModel); }
public ActionResult Index(int currentPage=1, string catagory = null, string tag = null) { catagory = catagory.Replace("_", " "); ViewBag.catagory = catagory; NewsViewModel viewModel = new NewsViewModel(); viewModel.Catagorys = new List<InfoCatagory>(); TempData["catagory"] = catagory; var q = from d in dbContext.Newss group d by d.CatagoryNews.CatagoryNewsName into counts select new { Group = counts.Key }; foreach (var item in q) { InfoCatagory news = new InfoCatagory { Name = item.Group.ToString()}; viewModel.Catagorys.Add(news); } viewModel.Catagorys.Insert(0, new InfoCatagory { Name = "All"}); List<string> allTag = dbContext.Newss.Select(x => x.Tag).ToList(); viewModel.Tags = new List<string>(); foreach (var item in allTag) { var list = item.Split('|'); viewModel.Tags = viewModel.Tags.Concat(list); } viewModel.Tags = viewModel.Tags.Distinct().Skip(1).OrderBy(s => s); if (tag == null) { if (catagory == "All") { viewModel.Newss = dbContext.Newss.Include(x => x.CatagoryNews).OrderBy(x => x.Date).Skip((currentPage - 1) * itemsPage).Take(itemsPage).ToList(); viewModel.PageNumbers = (int)Math.Ceiling((decimal)dbContext.Newss.Count() / (decimal)itemsPage); } else { viewModel.Newss = dbContext.Newss.Where(x => x.CatagoryNews.CatagoryNewsName == catagory).Include(x => x.CatagoryNews).OrderBy(x => x.Date).Skip((currentPage - 1) * itemsPage).Take(itemsPage).ToList(); viewModel.PageNumbers = (int)Math.Ceiling((decimal)dbContext.Newss.Where(x => x.CatagoryNews.CatagoryNewsName == catagory).Count() / (decimal)itemsPage); } } else { viewModel.Newss = dbContext.Newss.Where(x => x.Tag.Contains("|" + tag + "|")).Include(x => x.CatagoryNews).OrderBy(x => x.Date).Skip((currentPage - 1) * itemsPage).Take(itemsPage).ToList(); viewModel.PageNumbers = (int)Math.Ceiling((decimal)dbContext.Newss.Where(x => x.Tag.Contains(tag)).Count()/ (decimal)itemsPage); } viewModel.PriorityNews = dbContext.Newss.Where(x => x.IsPriority == true).ToList(); viewModel.CurrentPage = currentPage; return View(viewModel); }
public ActionResult Detail(int Id) { NewsDetailViewModel viewModel = new NewsDetailViewModel(); viewModel.Catagorys = new List<InfoCatagory>(); var q = from d in dbContext.Newss group d by d.CatagoryNews.CatagoryNewsName into counts select new { Count = counts.Count(), Group = counts.Key }; foreach (var item in q) { InfoCatagory news = new InfoCatagory { Name = item.Group.ToString()}; viewModel.Catagorys.Add(news); } viewModel.Catagorys.Insert(0, new InfoCatagory { Name = "All"}); viewModel.News = dbContext.Newss.Where(x => x.Id == Id).Include(t => t.CatagoryNews).SingleOrDefault(); viewModel.PriorityNews = dbContext.Newss.Where(x => x.IsPriority == true).ToList(); viewModel.Tags = viewModel.News.Tag.Split('|').Distinct().Skip(1); return View(viewModel); }