public async Task GetTotalHoursYearly() { await this.PopulateTimeEntries(defaultDate.AddYears(-1)); var totalHours = await webReportService.GetTotalHoursYearly(this.userId, defaultDate.Year); totalHours.TotalBillable.Should().BeGreaterOrEqualTo(0); totalHours.TotalSick.Should().BeGreaterOrEqualTo(0); totalHours.TotalNonBillable.Should().BeGreaterOrEqualTo(0); totalHours.TotalVacation.Should().BeGreaterOrEqualTo(0); await PopulateTimeEntries(defaultDate); var totalHours2 = await webReportService.GetTotalHoursYearly(this.userId, defaultDate.Year); totalHours2.TotalBillable.Should().Be(36); totalHours2.TotalSick.Should().Be(4); totalHours2.TotalVacation.Should().Be(8); totalHours2.TotalNonBillable.Should().Be(14); var totalHours3 = await webReportService.GetTotalHoursYearly(this.userId, defaultDate.AddYears(-2).Year); totalHours3.TotalBillable.Should().Be(0); totalHours3.TotalSick.Should().Be(0); totalHours3.TotalVacation.Should().Be(0); totalHours3.TotalNonBillable.Should().Be(0); var totalHours4 = await webReportService.GetTotalHoursYearly(this.userId, defaultDate.AddYears(-1).Year); totalHours4.TotalBillable.Should().Be(18); totalHours4.TotalSick.Should().Be(2); totalHours4.TotalVacation.Should().Be(4); totalHours4.TotalNonBillable.Should().Be(7); }
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)); }