/// <summary> /// Get list category and post data to show on homepage /// Get list of top 5 of post for each category /// </summary> /// <returns>List<CategoryViewModel></returns> public static List <CategoryViewModel> GetListCategoryShowOnHomePage() { List <CategoryViewModel> _return = new List <CategoryViewModel>(); try { using (var _context = new TDHEntities()) { //Return list List <CategoryViewModel> _returnList = new List <CategoryViewModel>(); //Get data var _list = _context.PROC_WEB_VIEW_HOME_PostByCategory().ToList(); //Get list category var _listCate = _list.Where(m => m.title.Length > 0); foreach (var item in _listCate) { _returnList.Add(new CategoryViewModel() { Title = item.title, Alias = item.alias, Posts = _list.Where(m => m.id == item.id && m.title.Length == 0) .Select(m => new PostViewModel() { Title = m.post_title, Alias = m.post_alias, Description = m.post_description, Image = m.post_image, CreateDate = m.post_create_date }) .ToList() }); } //Return list return(_returnList); } } catch (Exception ex) { throw new UserException(FILE_NAME, MethodInfo.GetCurrentMethod().Name, 500, ErrorMessage.ErrorService, ex); } }