Ejemplo n.º 1
0
        public WebReportServiceTest()
        {
            InMemoryDatabaseWithProjectsAndUsers inMemoryDatabase = new InMemoryDatabaseWithProjectsAndUsers();

            database         = inMemoryDatabase.Database;
            webReportService = new WebReportService(database);
            userId           = database.Users.First(x => x.UserId != null).UserId;
        }
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));
        }