public async Task <IActionResult> AddUserToProject(int projectId) { Global.ProjectId = projectId; var project = _projectRepository.GetProject(projectId); Global.Project = project; var userId = userManager.GetUserId(User); var currentUser = await userManager.FindByIdAsync(userId); var userClaims = await userManager.GetClaimsAsync(currentUser); Global.globalCurrentUserClaims = userClaims.ToList(); var IsDeveloperLevel = ClaimsLevel.IsDeveloper(userClaims.ToList(), projectId); if (IsDeveloperLevel == false) { return(RedirectToAction("AccessDenied", "Account")); } var viewModel = new AddUserToProjectViewModel { ProjectId = projectId }; return(View(viewModel)); }
public async Task <IActionResult> ListUsers(int projectId) { Global.ProjectId = projectId; var project = _projectRepository.GetProject(projectId); Global.Project = project; var users = new List <IdentityUser>(); var userId = userManager.GetUserId(User); var currentUser = await userManager.FindByIdAsync(userId); var userClaims = await userManager.GetClaimsAsync(currentUser); Global.globalCurrentUserClaims = userClaims.ToList(); var IsDeveloperLevel = ClaimsLevel.IsDeveloper(userClaims.ToList(), projectId); if (IsDeveloperLevel == 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 uId in projectUsers) { var user = await userManager.FindByIdAsync(uId); if (user != null && !users.Contains(user)) { users.Add(user); } } var viewModel = new ListUsersViewModel { OwnerId = project.OwnerId, Project = project, ProjectId = projectId, ProjectUsers = users }; return(View(viewModel)); }
public async Task <IActionResult> IssueDetails(IssueDetailsViewModel model) { var userId = userManager.GetUserId(User); var currentUser = await userManager.FindByIdAsync(userId); var userClaims = await userManager.GetClaimsAsync(currentUser); Global.globalCurrentUserClaims = userClaims.ToList(); var IsManagerLevel = ClaimsLevel.IsManager(userClaims.ToList(), model.Issue.AssociatedProject); if (IsManagerLevel && model.Issue.AssigneeUserId != null) { var assignedUser = await userManager.FindByIdAsync(model.Issue.AssigneeUserId); model.Issue.AssigneeUserName = assignedUser.UserName; } var uniqueFileNames = new List <ScreenShots>(); if (Global.InitialScreenShots == true) { uniqueFileNames = await UploadScreenShotsToStorage(model.Issue.IssueId); } Global.InitialScreenShots = false; _issueRepository.AddScreenShots(uniqueFileNames); var originalIssue = _issueRepository.GetIssue(model.Issue.IssueId); if (model.Issue.Title == null) { model.Issue.Title = originalIssue.Title; } var IsDeveloperLevel = ClaimsLevel.IsDeveloper(userClaims.ToList(), model.Issue.AssociatedProject); if (IsDeveloperLevel) { foreach (var property in originalIssue.GetType().GetProperties()) { if (property.Name == "AssigneeUserId") { continue; } var oldValue = ""; var newValue = ""; if (property.GetValue(model.Issue) != null) { newValue = property.GetValue(model.Issue).ToString(); } if (property.GetValue(originalIssue) != null) { oldValue = property.GetValue(originalIssue).ToString(); } if (newValue != oldValue) { var changes = new IssueHistory { AssociatedIssueId = originalIssue.IssueId, DateModified = DateTime.Now, NewValue = newValue, OldValue = oldValue, Property = property.Name }; _issueRepository.AddIssueHistory(changes); } } } var issue = new Issue(); if (IsDeveloperLevel) { model.Issue.ScreenShots = uniqueFileNames; model.Issue.ScreenShots.AddRange(_issueRepository.ScreenShots(model.Issue.IssueId)); issue = _issueRepository.Update(model.Issue); } else { issue = originalIssue; issue.ScreenShots = uniqueFileNames; issue.ScreenShots.AddRange(_issueRepository.ScreenShots(model.Issue.IssueId)); } Console.WriteLine(issue.IssueId); var project = _projectRepository.GetProject(issue.AssociatedProject); var projectName = project.ProjectName; issue.Comments = _issueRepository.Comments(issue.IssueId); var issueHistory = _issueRepository.GetIssueHistories(issue.IssueId); 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 uId in projectUsers) { var user = await userManager.FindByIdAsync(uId); if (user != null && !users.Contains(user)) { users.Add(user); } } var screenshots = _issueRepository.ScreenShots(model.Issue.IssueId); var viewModel = new IssueDetailsViewModel { Issue = issue, IssueHistories = issueHistory, Updated = 1, ProjectId = issue.AssociatedProject, Source = screenshots, ProjectUsers = users, ProjectName = projectName }; return(View(viewModel)); }