Ejemplo n.º 1
0
        public async Task GetAvailableMonths_getsMonths()
        {
            var months = await webReportService.GetUserAvailableMonths(userId);

            months.Should().NotBeEmpty();
            months.FirstOrDefault().Value.Should().Be($"{defaultDate.Year}-{defaultDate.Month}-01");
        }
Ejemplo n.º 2
0
        public async Task <ViewResult> Index(string selectedMonth = null)
        {
            var userId = await GetUserId();

            var webReportService    = new WebReportService(dbContext);
            var userAvailableMonths = await webReportService.GetUserAvailableMonths(userId);

            DateTime?selectedDate = null;

            if (selectedMonth == null)
            {
                selectedMonth = userAvailableMonths.FirstOrDefault()?.Value;
            }

            if (!String.IsNullOrEmpty(selectedMonth) && DateTime.TryParse(selectedMonth, out DateTime selectedDate2))
            {
                selectedDate = selectedDate2;
            }

            var projectService = new ProjectService(dbContext);
            var items          = await webReportService.GetUserReport(userId, selectedDate ?? DateTime.UtcNow);

            var model = new UserRecordHoursViewModel()
            {
                Hours         = items.ToImmutableList(),
                TimeEntryType = TimeEntryTypeEnum.BillableProject,
                Projects      = (await projectService.GetAllProjects()).ToImmutableList(),
                Name          = items.Any() ? items.First().Name : string.Empty,
                Date          = DateTime.UtcNow.Date,
                Months        = userAvailableMonths,
                SelectedMonth = selectedMonth,
                TotalYearly   = await webReportService.GetTotalHoursYearly(userId, selectedDate?.Year),
                TotalMonthly  = await webReportService.GetTotalHoursMonthly(userId, selectedDate?.Month)
            };

            return(View(model));
        }