//[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)); }
public async Task <IActionResult> AddBug(AddNewBug newbug) { if (ModelState.IsValid) { 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(), newbug.NewBugAttributes.AssociatedProject); if (UserIsMangerLevel && newbug.NewBugAttributes.AssigneeUserId != null) { var assignedUser = await userManager.FindByIdAsync(newbug.NewBugAttributes.AssigneeUserId); newbug.NewBugAttributes.AssingeeUserName = assignedUser.UserName; } newbug.NewBugAttributes.ReporterID = userManager.GetUserId(HttpContext.User); newbug.NewBugAttributes.ReporterUserName = userManager.GetUserName(HttpContext.User); newbug.NewBugAttributes.EnteredDate = DateTime.Now; var bug = _bugRepository.Add(newbug.NewBugAttributes); if (bug.Title == null) { bug.Title = $"bug{bug.BugId}"; bug = _bugRepository.Update(bug); } var projectBug = new ProjectBugs { BugId = bug.BugId, ProjectId = bug.AssociatedProject }; _projectRepository.AddProjectBugs(projectBug); List <ScreenShots> uniqueFileNames = new List <ScreenShots>(); if (GlobalVar.InitialScreenShots == true) { uniqueFileNames = await UploadScreenShotsToStorage(bug.BugId); } GlobalVar.InitialScreenShots = false; _bugRepository.AddScreenShots(uniqueFileNames); return(RedirectToAction("BugDetails", new { bugId = bug.BugId })); } return(View()); }