Beispiel #1
0
        /// <summary>
        /// Get timesheets for dates for list of projects.
        /// </summary>
        /// <param name="calendarStartDate">The start date from which timesheets to get.</param>
        /// <param name="calendarEndDate">The end date up to which timesheets to get.</param>
        /// <param name="projects">Projects between specified start and end date along with task details.</param>
        /// <param name="filledTimesheets">Timesheets of a user which were filled within specified start and end date</param>
        /// <returns>Returns list of timesheets.</returns>
        private List <UserTimesheet> GetTimesheetsForDates(DateTime calendarStartDate, DateTime calendarEndDate, List <Project> projects, List <TimesheetEntity> filledTimesheets)
        {
            var           timesheetDetails = new List <UserTimesheet>();
            UserTimesheet timesheetData    = null;

            // Iterate on total number of days between specified start and end date to get timesheet data of each day.
            for (int i = 0; i <= calendarEndDate.Subtract(calendarStartDate).TotalDays; i++)
            {
                timesheetData = new UserTimesheet
                {
                    TimesheetDate = calendarStartDate.AddDays(i).Date,
                };

                // Retrieves projects of particular calendar date ranges in specified start and end date.
                var filteredProjects = projects.Where(project => timesheetData.TimesheetDate >= project.StartDate && timesheetData.TimesheetDate <= project.EndDate);

                if (filteredProjects.IsNullOrEmpty())
                {
                    continue;
                }

                timesheetData.ProjectDetails = new List <ProjectDetails>();

                // Iterate on each project to get task and timesheet details.
                foreach (var project in filteredProjects)
                {
                    timesheetData.ProjectDetails.Add(new ProjectDetails
                    {
                        Id               = project.Id,
                        Title            = project.Title,
                        TimesheetDetails = project.Tasks.Select(task => new TimesheetDetails
                        {
                            TaskId          = task.Id,
                            TaskTitle       = task.Title,
                            Hours           = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id && timesheet.TimesheetDate.Date == timesheetData.TimesheetDate.Date).ToList().Select(x => x.Hours).FirstOrDefault(),
                            ManagerComments = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id && timesheet.TimesheetDate.Date == timesheetData.TimesheetDate.Date).Select(x => x.ManagerComments).FirstOrDefault(),
                            Status          = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id && timesheet.TimesheetDate.Date == timesheetData.TimesheetDate.Date).Select(x => x.Status).FirstOrDefault(),
                        }).ToList(),
                    });
                }

                timesheetDetails.Add(timesheetData);
            }

            return(timesheetDetails);
        }
Beispiel #2
0
        /// <summary>
        /// Gets all active projects along with tasks assigned to user between specified date range.
        /// </summary>
        /// <param name="calendarStartDate">The start date from which timesheets to get.</param>
        /// <param name="calendarEndDate">The end date up to which timesheets to get.</param>
        /// <param name="userObjectId">The user Id of which projects to get.</param>
        /// <returns>Returns all active projects assigned to user on particular date.</returns>
        public IEnumerable <UserTimesheet> GetProjects(DateTime calendarStartDate, DateTime calendarEndDate, Guid userObjectId)
        {
            // Get projects between specified start and end date along with task details.
            var projects = this.Context.Projects
                           .Where(project => ((project.StartDate.Date >= calendarStartDate.Date && project.StartDate.Date <= calendarEndDate.Date) ||
                                              (project.StartDate.Date < calendarStartDate.Date && project.EndDate.Date >= calendarStartDate.Date)) && project.Members.Where(member => member.UserId == userObjectId).Any())
                           .Include(project => project.Tasks)
                           .ToList();

            // Get timesheets of a user which were filled within specified start and end date.
            var filledTimesheets = this.Context.Timesheets
                                   .Where(timesheet => timesheet.UserId.Equals(userObjectId) &&
                                          timesheet.TimesheetDate.Date >= calendarStartDate.Date &&
                                          timesheet.TimesheetDate.Date <= calendarEndDate.Date)
                                   .ToList();

            var           timesheetDetails = new List <UserTimesheet>();
            UserTimesheet timesheetData    = null;

            // Iterate on total number of days between specified start and end date to get timesheet data of each day.
            for (int i = 0; i <= calendarEndDate.Subtract(calendarStartDate).TotalDays; i++)
            {
                timesheetData = new UserTimesheet
                {
                    TimesheetDate = calendarStartDate.AddDays(i).Date,
                };

                // Retrieves projects of particular calendar date ranges in specified start and end date.
                var filteredProjects = projects.Where(project => timesheetData.TimesheetDate >= project.StartDate && timesheetData.TimesheetDate <= project.EndDate);

                if (filteredProjects.IsNullOrEmpty())
                {
                    continue;
                }

                timesheetData.ProjectDetails = new List <ProjectDetails>();

                // Iterate on each project to get task and timesheet details.
                foreach (var project in filteredProjects)
                {
                    timesheetData.ProjectDetails.Add(new ProjectDetails
                    {
                        Id               = project.Id,
                        Title            = project.Title,
                        EndDateInUtc     = project.EndDate,
                        StartDateInUtc   = project.StartDate,
                        TimesheetDetails = project.Tasks.Select(task => new TimesheetDetails
                        {
                            TaskId          = task.Id,
                            TaskTitle       = task.Title,
                            Hours           = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id && timesheet.TimesheetDate.Date == timesheetData.TimesheetDate.Date).ToList().Select(x => x.Hours).FirstOrDefault(),
                            ManagerComments = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id && timesheet.TimesheetDate.Date == timesheetData.TimesheetDate.Date).Select(x => x.ManagerComments).FirstOrDefault(),
                            Status          = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id && timesheet.TimesheetDate.Date == timesheetData.TimesheetDate.Date).Select(x => x.Status).FirstOrDefault(),
                        }).ToList(),
                    });
                }

                timesheetDetails.Add(timesheetData);
            }

            return(timesheetDetails);
        }
Beispiel #3
0
        /// <summary>
        /// Gets timesheets of user between specified date range.
        /// </summary>
        /// <param name="calendarStartDate">The start date from which timesheets to get.</param>
        /// <param name="calendarEndDate">The end date up to which timesheets to get.</param>
        /// <param name="userObjectId">The user Id of which timesheets to get.</param>
        /// <returns>Returns timesheets of user on particular date range.</returns>
        public async Task <IEnumerable <UserTimesheet> > GetTimesheetsAsync(DateTime calendarStartDate, DateTime calendarEndDate, Guid userObjectId)
        {
            calendarStartDate = calendarStartDate.Date;
            calendarEndDate   = calendarEndDate.Date;

            var projects = await this.repositoryAccessors.ProjectRepository.GetProjectsAsync(calendarStartDate, calendarEndDate, userObjectId);

            var filledTimesheets = await this.repositoryAccessors.TimesheetRepository.GetTimesheetsAsync(calendarStartDate, calendarEndDate, userObjectId);

            var           timesheetDetails = new List <UserTimesheet>();
            UserTimesheet timesheetData    = null;

            double totalDays = calendarEndDate.Subtract(calendarStartDate).TotalDays;

            // Iterate on total number of days between specified start and end date to get timesheet data of each day.
            for (int i = 0; i <= totalDays; i++)
            {
                timesheetData = new UserTimesheet
                {
                    TimesheetDate = calendarStartDate.AddDays(i),
                };

                // Retrieves projects of particular calendar date ranges in specified start and end date.
                var filteredProjects = projects.Where(project => timesheetData.TimesheetDate >= project.StartDate.Date &&
                                                      timesheetData.TimesheetDate <= project.EndDate.Date);

                if (filteredProjects.IsNullOrEmpty())
                {
                    continue;
                }

                timesheetData.ProjectDetails = new List <ProjectDetails>();

                // Iterate on each project to get task and timesheet details.
                foreach (var project in filteredProjects)
                {
                    var memberDetails = project.Members.Where(member => member.UserId == userObjectId).FirstOrDefault();

                    if (memberDetails == null)
                    {
                        timesheetDetails.Add(timesheetData);
                        continue;
                    }

                    // Filter out valid tasks.
                    var filteredTasks = project.Tasks.Where(task => !task.IsRemoved &&
                                                            (!task.IsAddedByMember || (task.MemberMapping != null && task.MemberMappingId == memberDetails.Id)) &&
                                                            (timesheetData.TimesheetDate >= task.StartDate && timesheetData.TimesheetDate <= task.EndDate));

                    timesheetData.ProjectDetails.Add(new ProjectDetails
                    {
                        Id               = project.Id,
                        Title            = project.Title,
                        StartDate        = project.StartDate,
                        EndDate          = project.EndDate,
                        TimesheetDetails = filteredTasks.Select(task =>
                        {
                            var timesheetFilledForTask = filledTimesheets.Where(timesheet => timesheet.TaskId == task.Id &&
                                                                                timesheet.TimesheetDate == timesheetData.TimesheetDate).FirstOrDefault();

                            return(new TimesheetDetails
                            {
                                TaskId = task.Id,
                                TaskTitle = task.Title,
                                IsAddedByMember = task.IsAddedByMember,
                                StartDate = task.StartDate.Date,
                                EndDate = task.EndDate.Date,
                                Hours = timesheetFilledForTask == null ? 0 : timesheetFilledForTask.Hours,
                                ManagerComments = timesheetFilledForTask == null ? string.Empty : timesheetFilledForTask.ManagerComments,
                                Status = timesheetFilledForTask == null ? (int)TimesheetStatus.None : timesheetFilledForTask.Status,
                            });
                        }).ToList(),
                    });
                }

                timesheetDetails.Add(timesheetData);
            }

            return(timesheetDetails);
        }