public IActionResult Category(Guid id, UsageDropDownTypes?type) { var category = _context.Categories.FirstOrDefault(c => c.Id == id); if (category == null || string.IsNullOrEmpty(category.Name)) { return(View("Index")); } var usageType = (type.HasValue) ? type.Value : UsageDropDownTypes.LastMonth; var viewModel = new CategoryHomeViewModel(usageType) { Category = category }; viewModel.WebLinks = _context.WebLinks.Where(wl => wl.WebLinkCategories.Any(c => c.CategoryId == id)) .OrderByDescending(wl => wl.CreatedDateTime) .Select(wl => new WebLinkViewModel { WebLinkId = wl.Id, Name = wl.Name, Url = wl.Url, CurrentCount = wl.Usages.Count(), LastVisitedDateTime = (wl.Usages.Any()) ? wl.Usages.Max(u => u.CreatedDateTime) : DateTime.MinValue, Categories = wl.WebLinkCategories.Select(c => new CategoryViewModel { CategoryId = c.Category.Id, Name = c.Category.Name }).ToList() }) .ToList(); var usages = _context.Usages.Where(u => u.WebLink.WebLinkCategories.Any(wlc => wlc.CategoryId == id)).ToList(); viewModel.Usages = usages; var usageData = new List <UsageDataPerUnitViewModel>(); if (usages != null && usages.Count != 0) { foreach (var date in viewModel.UsageTimelineDates) { var usageCount = usages.Where(u => u.CreatedDateTime.Date == date.Date).Count(); var usageDataPerUnitViewModel = new UsageDataPerUnitViewModel { NoOfVisits = usageCount, UnitName = date.ToShortTimeString(), SelectedColor = Color.Blue }; usageData.Add(usageDataPerUnitViewModel); } } viewModel.UsageData = usageData; return(View(viewModel)); }
public ActionResult Categories(string category) { // Blog Listing Homepage if (String.IsNullOrEmpty(category)) { var model = new CategoryHomeViewModel(); return(View("~/Views/Blog/CategoriesHome.cshtml", model)); } // Individual Blog else { var model = new CategorySingleViewModel(category, Server); return(View("~/Views/Blog/CategoriesSingle.cshtml", model)); } }
public ActionResult Category() { var lstGroup = _groupService.GetGroupActive(); var lstGroupViewModel = Mapper.Map <IEnumerable <Group>, IEnumerable <GroupViewModel> >(lstGroup); foreach (var item in lstGroupViewModel) { item.Products = Mapper.Map <IEnumerable <Product>, IEnumerable <ProductViewModel> >(_groupService.GetListProductByGroupActive(item.ID, 6)); } var model = _productCategoryService.GetAllByStatus(); var lstProductCategoryVm = Mapper.Map <IEnumerable <ProductCategory>, IEnumerable <ProductCategoryViewModel> >(model); var categoryHomeVm = new CategoryHomeViewModel(); categoryHomeVm.MenuCategory = lstProductCategoryVm; categoryHomeVm.Groups = lstGroupViewModel; return(PartialView(categoryHomeVm)); }