public async Task<ActionResult> Index() { postRepository = uow.Repository<Post>(); adRepository = uow.Repository<Ad>(); var pageIndex = postRepository.Get(p => p.RouteName == "Index" && p.Status == 1).FirstOrDefault(); var pageIndexViewModel = new PageViewModel(); if (pageIndex != null) { pageIndexViewModel.Title = pageIndex.Title; pageIndexViewModel.PageContent = pageIndex.Content; } var adsIndex = await adRepository.Get(a => a.Place == 0 && a.Type == 0 && a.Status == 1).OrderBy(a => a.SortOrder).ToListAsync(); var adsViewModel = new List<AdViewModel>(); if (adsIndex != null || adsIndex.Count() > 0) { foreach (var item in adsIndex) { adsViewModel.Add(new AdViewModel { Name = item.Name, Description = item.Description, Src = item.Src, Link = item.Link }); } } var viewModel = new HomeViewModel(pageIndexViewModel, adsViewModel); if (pageIndex != null) { viewModel.HomeContent = pageIndexViewModel; } return View(viewModel); }
public async Task<ActionResult> About(int? id) { postRepository = uow.Repository<Post>(); var viewModel = new PageViewModel(); Post pageAbout; if (id > 0) { pageAbout = postRepository.FindById(id); } else { pageAbout = await postRepository.Get(p => p.RouteName.ToLower() == "about" && p.Parent == 0 && p.Status == 1).FirstOrDefaultAsync(); } viewModel.Id = pageAbout.Id; viewModel.Title = pageAbout.Title; viewModel.PageContent = pageAbout.Content; return View(viewModel); }
public HomeViewModel(PageViewModel homeContent, List<AdViewModel> homeAds) { this.HomeContent = HomeContent; this.HomeAds = homeAds; }
public PartialViewResult PageSidebar(string action, int id) { var viewModel = new PageViewModel(); postRepository = uow.Repository<Post>(); var pages = postRepository.Get(p => p.PostType == "page" && p.RouteName.ToLower() == action.ToLower() && p.Status == 1).OrderBy(p => p.Id).ToList(); if (pages != null && pages.Count() > 0) { viewModel.Id = id; viewModel.Menu = new List<PageMenu>(); foreach (var item in pages) { viewModel.Menu.Add(new PageMenu( item.Id, item.RouteName, item.Title, item.RouteName )); } } return PartialView("_PageSidebar", viewModel); }