public IViewComponentResult Invoke(MonthViewPagerViewModel pagerModel) { MonthViewViewModel model = null; if (ModelState.IsValid) { try { model = new MonthViewViewModel(); model.Pager = pagerModel; UIUser usr = GetUserInfo(); var list = MonthExpensesContext.LoadUserMonthExpenses(usr, pagerModel.SelectedMonth.MonthStartTs, pagerModel.SelectedMonth.MonthEndTs).Select(x => AutoMapperFactory.MonthViewItemViewModel_UIMonthExpense.CreateMapper().Map <MonthViewItemViewModel>(new UIMonthExpense(x))).ToList(); model.MonthViewItems = list; if (list.Count() != 0) { model.MonthTotalCost = list.Select(x => x.TotalCost).Sum(); } } catch (Exception ex) { ViewData["WarningMessage"] = ex.Message; } return(View(model)); } else { model = new MonthViewViewModel(); model.MonthViewItems = new List <MonthViewItemViewModel>(); model.Pager = pagerModel; return(View(model)); } }
private List <MonthViewViewModel> GetMonthsViewModel(DateTime dateTime, bool wholeYear = false) { string languageFilter = httpContextAccessor.HttpContext.Request.Headers["Accept-Language"]; ViewBag.PreviousMonth = dateTime.AddMonths(-1).Date; ViewBag.NextMonth = dateTime.AddMonths(1).Date; ViewBag.CurrentMonth = dateTime.Date; //unique list of years for the top of archives var daysWithEntries = archiveManager.GetDaysWithEntries(); ViewBag.Years = daysWithEntries.Select(i => i.Year).Distinct(); EntryCollection entries; if (wholeYear) { entries = archiveManager.GetEntriesForYear(dateTime, languageFilter); } else { entries = archiveManager.GetEntriesForMonth(dateTime, languageFilter); } //TODO: Do I need this? //entries = new EntryCollection(entries.OrderBy(e => e.CreatedUtc)); DefaultPage(ARCHIVE); return(MonthViewViewModel.Create(dateTime, entries, mapper)); }
private List <MonthViewViewModel> GetMonthsViewModel(DateTime dateTime, bool wholeYear = false) { string languageFilter = httpContextAccessor.HttpContext.Request.Headers["Accept-Language"]; ViewBag.PreviousMonth = dateTime.AddMonths(-1).Date; ViewBag.NextMonth = dateTime.AddMonths(1).Date; ViewBag.CurrentMonth = dateTime.Date; var stopWatch = new Stopwatch(); stopWatch.Start(); //unique list of years for the top of archives var daysWithEntries = archiveManager.GetDaysWithEntries(); ViewBag.Years = daysWithEntries.Select(i => i.Year).Distinct(); EntryCollection entries; if (wholeYear) { entries = archiveManager.GetEntriesForYear(dateTime, languageFilter); } else { entries = archiveManager.GetEntriesForMonth(dateTime, languageFilter); } stopWatch.Stop(); logger.LogInformation(new DasBlog.Services.ActivityLogs.EventDataItem(EventCodes.Site, null, $"ArchiveController (Date: {dateTime.ToLongDateString()}; Year: {wholeYear}) Time elapsed: {stopWatch.Elapsed.TotalMilliseconds}ms")); DefaultPage(ARCHIVE); return(MonthViewViewModel.Create(dateTime, entries, mapper)); }
private MonthViewViewModel GetMonthsViewModel(DateTime dateTime) { string languageFilter = httpContextAccessor.HttpContext.Request.Headers["Accept-Language"]; ViewBag.PreviousMonth = dateTime.AddMonths(-1).Date; ViewBag.NextMonth = dateTime.AddMonths(1).Date; ViewBag.CurrentMonth = dateTime.Date; var entries = archiveManager.GetEntriesForMonth(dateTime, languageFilter); return(MonthViewViewModel.Create(dateTime, entries, mapper)); }