private TimeRecordsListViewModel PrepareTimeRecords(TimeRecordsListViewModel model, IEnumerable <TimeRecordInfo> timeRecords, Guid?selectedProject, Guid?selectedPerson) { model.SelectedEndDate = DateTime.Now.Date; model.SelectedStartDate = DateTime.Now.Date; model.Projects = _projectQueryService.GetProjects().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }); model.Statuses = this.GetStatuses(); var projectId = selectedProject == null?Guid.Parse(model.Projects.First().Value) : (Guid)selectedProject; var isUserProjectManager = _userQueryService.IsUserProjectManager(new ProjectId(projectId), new UserId(UserContext.Current.UserId)); model.IsProjectManager = isUserProjectManager; model.People = this.GetPeople(isUserProjectManager, projectId); var userReporterId = selectedPerson == null?Guid.Parse(model.People.First().Value) : (Guid)selectedPerson; var userReporter = _userQueryService.GetUser(new UserId(userReporterId)); model.User = new UserViewModel { LastName = userReporter.LastName, FirstName = userReporter.FirstName }; if (isUserProjectManager) { timeRecords = timeRecords.Where(x => x.Status == ProjectDomain.Model.DomainLayer.TimeRecordStatus.Notified); } model.Records = timeRecords.Select(x => new TimeRecordViewModel { StartDate = x.StartDate, EndDate = x.EndDate, Effort = x.Effort, Project = x.Project == null ? null : new ProjectVewModel { Name = x.Project.Name, ProjectId = x.Project.Id }, TimeRecordId = x.TimeRecordId, Status = (TimeRecordStatus)x.Status, Task = x.Task == null ? null : new TaskViewModel { TaskId = x.Task.TaskId, Title = x.Task.Title }, Description = this.TrimString(x.Description, 60), UserId = x.UserId, }).OrderBy(x => x.StartDate).ToArray(); return(model); }
public ActionResult Index(TimeRecordsListViewModel model) { var userId = new UserId(model.SelectedPerson); var timeRecords = _timeRecordQueryService.GetUserTimeRecords(userId) .Where(x => x.StartDate >= model.SelectedStartDate && x.EndDate <= model.SelectedEndDate && x.Project.Id == model.SelectedProject); if (model.SelectedStatus != TimeRecordStatus.All) { timeRecords = timeRecords.Where(x => x.Status == (ProjectDomain.Model.DomainLayer.TimeRecordStatus)model.SelectedStatus); } return(View(this.PrepareTimeRecords(model, timeRecords.ToList(), model.SelectedProject, model.SelectedPerson))); }
public ActionResult Index() { var model = new TimeRecordsListViewModel(); return(View(this.PrepareTimeRecords(model))); }
private TimeRecordsListViewModel PrepareTimeRecords(TimeRecordsListViewModel model) { return(this.PrepareTimeRecords(model, Enumerable.Empty <TimeRecordInfo>(), null, null)); }