//[Authorize(Policy = "DeveloperPolicy")] public async Task <IActionResult> AddUserToProject(int projectId) { GlobalVar.ProjectId = projectId; var project = projectRepository.GetProject(GlobalVar.ProjectId); GlobalVar.Project = project; var currentUserId = userManager.GetUserId(HttpContext.User); var currentUser = await userManager.FindByIdAsync(currentUserId); var claims = await userManager.GetClaimsAsync(currentUser); GlobalVar.globalCurrentUserClaims = claims.ToList(); var UserIsDeveloperLevel = UserClaimsLevel.IsDeveloper(claims.ToList(), projectId); if (UserIsDeveloperLevel == false) { return(RedirectToAction("AccessDenied", "Account")); } var viewModel = new AddUserToProjectViewModel { ProjectId = projectId }; return(View(viewModel)); }
//[Authorize(Policy = "DeveloperPolicy")] public async Task <IActionResult> ListUsers(int projectId) { GlobalVar.ProjectId = projectId; var users = new List <IdentityUser>(); var project = projectRepository.GetProject(projectId); GlobalVar.Project = project; var currentUserId = userManager.GetUserId(HttpContext.User); var currentUser = await userManager.FindByIdAsync(currentUserId); var claims = await userManager.GetClaimsAsync(currentUser); GlobalVar.globalCurrentUserClaims = claims.ToList(); var UserIsDeveloperLevel = UserClaimsLevel.IsDeveloper(claims.ToList(), projectId); if (UserIsDeveloperLevel == false) { return(RedirectToAction("AccessDenied", "Account")); } var projectUsers = new List <string>(); projectUsers.Add(project.OwnerId); if (project.UsersAssigned != null) { projectUsers.AddRange(project.UsersAssigned.Split(" ").ToList()); } foreach (var userId in projectUsers) { var user = await userManager.FindByIdAsync(userId); if (user != null && !users.Contains(user)) { users.Add(user); } } var viewModel = new ListUsersViewModel { Users = users, ProjectId = projectId, OwnerId = project.OwnerId }; return(View(viewModel)); }
public async Task <IActionResult> BugDetails(BugDetailsAndProjectNameAndId updatedBug) { var currentUserId = userManager.GetUserId(HttpContext.User); var currentUser = await userManager.FindByIdAsync(currentUserId); var claims = await userManager.GetClaimsAsync(currentUser); GlobalVar.globalCurrentUserClaims = claims.ToList(); var UserIsMangerLevel = UserClaimsLevel.IsManager(claims.ToList(), updatedBug.Bug.AssociatedProject); if (UserIsMangerLevel && updatedBug.Bug.AssigneeUserId != null) { var assignedUser = await userManager.FindByIdAsync(updatedBug.Bug.AssigneeUserId); updatedBug.Bug.AssingeeUserName = assignedUser.UserName; } List <ScreenShots> uniqueFileNames = new List <ScreenShots>(); if (GlobalVar.InitialScreenShots == true) { uniqueFileNames = await UploadScreenShotsToStorage(updatedBug.Bug.BugId); } GlobalVar.InitialScreenShots = false; var originalBug = _bugRepository.GetBug(updatedBug.Bug.BugId); if (updatedBug.Bug.Title == null) { updatedBug.Bug.Title = originalBug.Title; } var UserIsDeveloperLevel = UserClaimsLevel.IsDeveloper(claims.ToList(), updatedBug.Bug.AssociatedProject); if (UserIsDeveloperLevel) { foreach (var property in originalBug.GetType().GetProperties()) { if (property.Name == "AssigneeUserId") { continue; } var oldValue = ""; var newValue = ""; if (property.GetValue(updatedBug.Bug) != null) { newValue = property.GetValue(updatedBug.Bug).ToString(); } if (property.GetValue(originalBug) != null) { oldValue = property.GetValue(originalBug).ToString(); } if (oldValue != newValue) { var changes = new BugHistory { AssociatedBugId = originalBug.BugId, Property = property.Name, OldValue = oldValue, NewValue = newValue, DateChanged = DateTime.Now }; _bugRepository.AddHistoryEntry(changes); } } } var bug = new BugAttributes(); if (UserIsDeveloperLevel) { updatedBug.Bug.ScreenShots = uniqueFileNames; updatedBug.Bug.ScreenShots.AddRange(_bugRepository.ScreenShots(updatedBug.Bug.BugId)); bug = _bugRepository.Update(updatedBug.Bug); } else { //bug = _bugRepository.GetBug(updatedBug.Bug.BugId); bug = originalBug; bug.ScreenShots = uniqueFileNames; bug.ScreenShots.AddRange(_bugRepository.ScreenShots(updatedBug.Bug.BugId)); } var project = _projectRepository.GetProject(bug.AssociatedProject); var projectName = project.ProjectName; bug.Comments = _bugRepository.Comments(bug.BugId); var bugHistory = _bugRepository.GetBugHistories(bug.BugId); var users = new List <IdentityUser>(); var projectUsers = new List <string>(); projectUsers.Add(project.OwnerId); if (project.UsersAssigned != null) { projectUsers.AddRange(project.UsersAssigned.Split(" ").ToList()); } foreach (var userId in projectUsers) { var user = await userManager.FindByIdAsync(userId); if (user != null && !users.Contains(user)) { users.Add(user); } } var viewModel = new BugDetailsAndProjectNameAndId() { Bug = bug, ProjectName = projectName, ProjectId = bug.AssociatedProject, Updated = 1, //Src = new List<ScreenShots>(), Src = bug.ScreenShots, bugHistories = bugHistory, ProjectUsers = users }; return(View(viewModel)); }