private ProjectViewModel ToProjectViewModel(Project project) { var tasks = _taskRepository.GetAll().Where(p => p.ProjectId == project.ProjectId); var taskCount = tasks.Count(); var isAllTasksCompleted = tasks .All(s => !string.IsNullOrEmpty(s.Status) && string.Equals("Yes", s.Status, StringComparison.InvariantCultureIgnoreCase)); var manager = _userRepository.GetAll().FirstOrDefault(p => p.ProjectId == project.ProjectId); var managerName = ""; var managerId = 0; if (manager != null) { managerName = FormatName(manager); managerId = manager.UserId; } return(new ProjectViewModel { ProjectId = project.ProjectId, ProjectName = project.Title, StartDate = project.StartDate, EndDate = project.EndDate, Priority = project.Priority, Manager = managerName, UserId = managerId, Completed = isAllTasksCompleted ? "Yes" : "No", NumberOfTasks = taskCount }); }
public IEnumerable <TaskViewModel> GetAllTasksBL() { var parentTasks = _parentTaskBusiness .GetAll() .ToList(); var projects = _projectBusiness.GetAll(); var tasks = _taskRepository.GetAll(); var users = _userRepository.GetAll(); var models = new List <TaskViewModel>(); foreach (var task in tasks) { var parentTaskName = string.Empty; var status = "No"; var projectName = string.Empty; var managerName = string.Empty; var managerId = 0; var pt = parentTasks.FirstOrDefault(p => p.ParentTaskId == task.ParentTaskId); if (pt != null) { parentTaskName = pt.ParentTaskName; } var project = projects.FirstOrDefault(p => p.ProjectId == task.ProjectId); if (project != null) { projectName = project.ProjectName; } var user = users.FirstOrDefault(p => p.TaskId == task.TaskId); if (user != null) { managerName = string.Format("{0} {1}", user.FirstName, user.LastName); managerId = user.UserId; } models.Add(new TaskViewModel { TaskId = task.TaskId, TaskName = task.Title, ParentTaskName = parentTaskName, ParentTaskId = task.ParentTaskId, StartDate = task.StartDate, EndDate = task.EndDate, ProjectId = task.ProjectId, ProjectName = projectName, Priority = task.Priority, ManagerId = managerId, ManagerName = managerName, Status = string.IsNullOrEmpty(task.Status) ? status : task.Status }); } return(models); }
public IEnumerable <UserViewModel> GetAll() { var users = new List <UserViewModel>(); var entities = _userRepository.GetAll(); entities.ToList().ForEach(u => users.Add(ToUserViewModel(u))); return(users); }
public IEnumerable <ParentTaskViewModel> GetAll() { var entities = _parentTaskRepository.GetAll(); var models = new List <ParentTaskViewModel>(); entities.ToList().ForEach(p => models.Add(ToModel(p))); return(models); }
public IEnumerable <ProjectViewModel> GetAll() { var projects = new List <ProjectViewModel>(); var entities = _projectRepository.GetAll(); entities.ToList().ForEach(u => projects.Add(ToProjectViewModel(u))); return(projects); }