//[Authorize(Policy = "UserPolicy")] public async Task <IActionResult> ProjectBugs(int projectId) { GlobalVar.ProjectId = projectId; var project = _projectRepository.GetProject(projectId); GlobalVar.Project = project; var currentUserId = userManager.GetUserId(HttpContext.User); var user = await userManager.FindByIdAsync(currentUserId); var claims = await userManager.GetClaimsAsync(user); GlobalVar.globalCurrentUserClaims = claims.ToList(); var UserIsUserLevel = UserClaimsLevel.IsUser(claims.ToList(), projectId); if (UserIsUserLevel == false) { return(RedirectToAction("AccessDenied", "Account")); } var projectBugs = _bugRepository.GetAllProjectBugs(projectId); var viewModel = new ProjectDetailsAndAssociatedBugs() { Project = project, ProjectBugs = projectBugs, ProjectId = projectId }; return(View(viewModel)); }
//[Authorize(Policy = "UserPolicy")] public async Task <IActionResult> AddBug(int projectId) { GlobalVar.ProjectId = projectId; var initialCreate = new BugAttributes() { AssociatedProject = projectId, DueDate = DateTime.Today, }; 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 UserIsUserLevel = UserClaimsLevel.IsUser(claims.ToList(), projectId); if (UserIsUserLevel == false) { return(RedirectToAction("AccessDenied", "Account")); } 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 AddNewBug() { NewBugAttributes = initialCreate, ProjectId = projectId, ProjectUsers = users }; return(View(viewModel)); }
//[Authorize(Policy = "UserPolicy")] public async Task <IActionResult> BugDetails(int bugId) { var bug = _bugRepository.GetBug(bugId); GlobalVar.ProjectId = bug.AssociatedProject; var project = _projectRepository.GetProject(bug.AssociatedProject); 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 UserIsUserLevel = UserClaimsLevel.IsUser(claims.ToList(), bug.AssociatedProject); if (UserIsUserLevel == false) { return(RedirectToAction("AccessDenied", "Account")); } var screenShots = _bugRepository.ScreenShots(bugId); var projectName = project.ProjectName; var comments = _bugRepository.Comments(bugId); var bugHistory = _bugRepository.GetBugHistories(bugId); bug.Comments = comments; 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 = 0, Src = screenShots, bugHistories = bugHistory, ProjectUsers = users, CurrentUserName = HttpContext.User.Identity.Name }; //if (screenShots != null) //{ // foreach (var path in screenShots) // { // var imgPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "screenshots", path.FilePath); // using (FileStream stream = new FileStream(imgPath, FileMode.Open, FileAccess.Read)) // { // var image = Image.FromStream(stream); // using (var mStream = new MemoryStream()) // { // image.Save(mStream, ImageFormat.Jpeg); // var byteData = mStream.ToArray(); // string imreBase64Data = Convert.ToBase64String(byteData); // string imgDataURL = $"data:image/{path.FilePath.Split(".")[1]};base64,{imreBase64Data}"; // viewModel.Src.Add(new ScreenShots // { // id = path.id, // AssociatedBug = path.AssociatedBug, // FilePath = imgDataURL // }); // } // } // } //} return(View(viewModel)); }