Esempio n. 1
0
        //[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));
        }
Esempio n. 2
0
        public async Task <IActionResult> ProjectDetails(ProjectDetailsAndAssociatedBugs projectUpdates)
        {
            var originalProject = _projectRepository.GetProject(projectUpdates.Project.ProjectId);


            var userId = userManager.GetUserId(HttpContext.User);
            var user   = await userManager.FindByIdAsync(userId);

            var claims = await userManager.GetClaimsAsync(user);

            GlobalVar.globalCurrentUserClaims = claims.ToList();



            foreach (var property in originalProject.GetType().GetProperties())
            {
                var oldValue = "";
                var newValue = "";

                if (property.GetValue(projectUpdates.Project) != null)
                {
                    newValue = property.GetValue(projectUpdates.Project).ToString();
                }

                if (property.GetValue(originalProject) != null)
                {
                    oldValue = property.GetValue(originalProject).ToString();
                }

                if (oldValue != newValue)
                {
                    var changes = new ProjectHistory
                    {
                        AssociatedProjectId = originalProject.ProjectId,
                        Property            = property.Name,
                        OldValue            = oldValue,
                        NewValue            = newValue,
                        DateChanged         = DateTime.Now
                    };
                    _projectRepository.AddHistoryEntry(changes);
                }
            }


            var projectBugs    = _bugRepository.GetAllProjectBugs(projectUpdates.Project.ProjectId);
            var project        = _projectRepository.Update(projectUpdates.Project);
            var projectHistory = _projectRepository.GetProjectHistories(projectUpdates.Project.ProjectId);

            var viewModel = new ProjectDetailsAndAssociatedBugs()
            {
                Project          = project,
                ProjectBugs      = projectBugs,
                projectHistories = projectHistory,
                ProjectId        = GlobalVar.ProjectId
            };

            return(View(viewModel));
        }