/// <summary> /// TODO: Delete this when admin screens done! /// </summary> public static void TempInit() { AllProjects t3 = new AllProjects(); if (t3.Count == 0) { t3.Add(new Project { Id = Guid.NewGuid(), Description = "Test Project", Active = true }); t3.Save(); } AllTasks t1 = new AllTasks(); if (t1.Count == 0) { t1.Add(new Task { Id = Guid.NewGuid(), ProjectId = t3[0].Id, Description = "Test Task 1", Active = true }); t1.Save(); } AllUserTaskAccess t5 = new AllUserTaskAccess(); if (t5.Count == 0) { t5.Add(new UserTaskAccess { ProjectId = t3[0].Id, TaskId = t1[0].Id, UserId = new AllUsers()[0].UserId }); t5.Save(); } }
public static List <User> GetAllUsersForTask(Guid projectId, Guid taskId) { List <Guid> userIds = AllUserTaskAccess.GetUserIdsForProjectAndTask(projectId, taskId); if (userIds != null && userIds.Count > 0) { return(AllUsers.GetUsers(userIds)); } else { return(new List <User>()); } }
public static Task GetTaskById(Guid taskId, Guid projectId, Guid userId) { Task item = null; UserTaskAccess access = AllUserTaskAccess.GetForUserAndProjectAndTask(userId, projectId, taskId); //check if user has access to this task, if so, retrieve it if (access != null) { item = AllTasks.GetForId(taskId); } return(item); }
public static Project GetProjectForUser(Guid projectId, Guid userId) { Project item = null; List <Guid> access = AllUserTaskAccess.GetTaskIdsForUserAndProject(userId, projectId); //check if user has access to this project, if so, retrieve it if (access != null && access.Count > 0) { item = AllProjects.GetForId(projectId, false); } return(item); }
/// <summary> /// Gets the list of projects for a user /// </summary> /// <param name="usr">The user with access to the projects</param> /// <param name="activeOnly">Indicator of active projects or not</param> /// <returns>Populated List of Projects if there are any, otherwise an empty list<Project></returns> public static List <Project> GetProjectsForUser(Guid userId, bool activeOnly) { List <Project> items = new List <Project>(); foreach (Guid currItem in AllUserTaskAccess.GetProjectIdsForUser(userId)) { Project currProj = AllProjects.GetForId(currItem, activeOnly); if (currProj != null) { items.Add(currProj); } } items.Sort(); return(items); }
/// <summary> /// Gets the list of tasks for a project and a user /// </summary> /// <param name="projectId">The project which the tasks belong to</param> /// <param name="userId">The user with access to the tasks</param> /// <param name="activeOnly">Indicator of active tasks or not</param> /// <returns>Populated list of tasks if there are any, otherwise an empty list</returns> public static List <Task> GetTasksForProjectAndUser(Guid projectId, Guid userId, bool activeOnly) { List <Task> items = new List <Task>(); foreach (Guid currItem in AllUserTaskAccess.GetTaskIdsForUserAndProject(userId, projectId)) { Task currTask = AllTasks.GetForIdAndProject(currItem, projectId, activeOnly); if (currTask != null) { items.Add(currTask); } } items.Sort(); return(items); }
public static List <ValidationMessage> RemoveUserAccess( ValidatableParameter <string> projectId, ValidatableParameter <string> taskId, ValidatableParameter <Guid> userId ) { List <ValidationMessage> errors = new List <ValidationMessage>(); Guid projId = Guid.Empty; Guid tskId = Guid.Empty; try { projId = new Guid(projectId.Value); } catch (FormatException) { errors.Add(new ValidationMessage { MessageText = "Project Id must be in the format dddddddd-dddd-dddd-dddd-dddddddddddd", Source = projectId.Source }); } try { tskId = new Guid(taskId.Value); } catch (FormatException) { errors.Add(new ValidationMessage { MessageText = "Task Id must be in the format dddddddd-dddd-dddd-dddd-dddddddddddd", Source = taskId.Source }); } if (userId.Value == Guid.Empty) { errors.Add(new ValidationMessage { MessageText = "User must be supplied", Source = userId.Source }); } else { //check for existing relationship UserTaskAccess existItem = AllUserTaskAccess.GetForUserAndProjectAndTask(userId.Value, projId, tskId); if (existItem == null) { errors.Add(new ValidationMessage { MessageText = string.Format("User does not have access to Task with Id {0}", existItem.TaskId.ToString()), Source = userId.Source }); } } //perform add if no errors if (errors.Count == 0) { AllUserTaskAccess items = new AllUserTaskAccess(); UserTaskAccess existItem = items.Where(i => i.ProjectId == projId && i.TaskId == tskId && i.UserId == userId.Value).Single(); if (existItem != null) { items.Remove(existItem); } items.Save(); } return(errors); }