public async Task <ActionResult> Index(int?id) { try { int pageStart = 0; int currentPage = 1; if (id.HasValue) { pageStart = id.Value < 1 ? 0 : id.Value - 1; currentPage = id.Value < 1 ? 1 : id.Value; } var newsResult = await _eventsManagementServices.GetPagedEventsWithTotalAsync(pageStart *this.PageSize, this.PageSize); var otheNewsResult = await _newsManagementServices.GetLatestNewsAsync(4); var viewModel = newsResult.ToEventsListViewModel(); viewModel.PageSize = this.PageSize; viewModel.CurrentPage = currentPage; viewModel.NewsList = otheNewsResult.ToRelatedNewsViewModel(); return(View(viewModel)); } catch (Exception ex) { return(View("Error", ex)); } }
// GET: News public async Task <ActionResult> Details(string id) { try { Guid newsId = new Guid(id); var newsResult = await _newsManagementServices.GetByIdAsync(newsId); var eventsResult = await _eventsManagementServices.GetLatestEventsAsync(3); var otheNewsResult = await _newsManagementServices.GetLatestNewsAsync(4); var viewModel = newsResult.ToViewModel(); viewModel.OtherNewsList = otheNewsResult.ToRelatedNewsViewModel(); viewModel.EventsList = eventsResult.ToViewModel(); return(View(viewModel)); } catch (Exception ex) { return(View("Error", ex)); } }