Ejemplo n.º 1
0
        public IActionResult AddEditFrameworkCompetency(int frameworkId, int?frameworkCompetencyGroupId, int frameworkCompetencyId = 0)
        {
            var adminId  = GetAdminId();
            var userRole = frameworkService.GetAdminUserRoleForFrameworkId(adminId, frameworkId);

            if (userRole < 2)
            {
                return(StatusCode(403));
            }
            var frameworkCompetency = new FrameworkCompetency();

            if (frameworkCompetencyId > 0)
            {
                frameworkCompetency = frameworkService.GetFrameworkCompetencyById(frameworkCompetencyId);
            }
            var detailFramework = frameworkService.GetDetailFrameworkByFrameworkId(frameworkId, adminId);

            if (detailFramework == null || frameworkCompetency == null)
            {
                return(StatusCode(404));
            }
            var model = new FrameworkCompetencyViewModel()
            {
                DetailFramework            = detailFramework,
                FrameworkCompetencyGroupId = frameworkCompetencyGroupId,
                FrameworkCompetency        = frameworkCompetency,
            };

            return(View("Developer/Competency", model));
        }
        public IActionResult AddEditFrameworkCompetency(int frameworkId, FrameworkCompetency frameworkCompetency, int?frameworkCompetencyGroupId, int frameworkCompetencyId = 0, int[] selectedFlagIds = null)
        {
            frameworkCompetency.Description = SanitizerHelper.SanitizeHtmlData(frameworkCompetency.Description);
            if (!ModelState.IsValid)
            {
                ModelState.Remove(nameof(FrameworkCompetency.Name));
                ModelState.AddModelError(nameof(FrameworkCompetency.Name), "Please enter a valid competency statement (between 3 and 500 characters)");
                var detailFramework = frameworkService.GetDetailFrameworkByFrameworkId(frameworkId, GetAdminId());
                var competencyFlags = frameworkService.GetCompetencyFlagsByFrameworkId(frameworkId, frameworkCompetency?.CompetencyID).ToList();
                if (competencyFlags != null)
                {
                    competencyFlags.ForEach(f => f.Selected = selectedFlagIds.Contains(f.FlagId));
                }
                if (detailFramework == null)
                {
                    return(StatusCode((int)HttpStatusCode.NotFound));
                }
                var model = new FrameworkCompetencyViewModel()
                {
                    DetailFramework            = detailFramework,
                    FrameworkCompetencyGroupId = frameworkCompetencyId,
                    FrameworkCompetency        = frameworkCompetency,
                    CompetencyFlags            = competencyFlags
                };
                return(View("Developer/Competency", model));
            }
            var adminId  = GetAdminId();
            var userRole = frameworkService.GetAdminUserRoleForFrameworkId(adminId, frameworkId);

            if (userRole < 2)
            {
                return(StatusCode((int)HttpStatusCode.Forbidden));
            }
            if (frameworkCompetency.Id > 0)
            {
                frameworkService.UpdateFrameworkCompetency(frameworkCompetencyId, frameworkCompetency.Name, frameworkCompetency.Description, adminId);
                frameworkService.UpdateCompetencyFlags(frameworkId, frameworkCompetency.CompetencyID, selectedFlagIds);
                return(new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId, frameworkCompetencyId }) + "#fc-" + frameworkCompetencyId.ToString()));
            }
            var newCompetencyId = frameworkService.InsertCompetency(frameworkCompetency.Name, frameworkCompetency.Description, adminId);

            if (newCompetencyId > 0)
            {
                var newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId);
                frameworkService.UpdateCompetencyFlags(frameworkId, newCompetencyId, selectedFlagIds);
                return(new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId, frameworkCompetencyId }) + "#fc-" + newFrameworkCompetencyId.ToString()));
            }
            logger.LogWarning($"Attempt to add framework competency failed for admin {adminId}.");
            return(StatusCode((int)HttpStatusCode.Forbidden));
        }
Ejemplo n.º 3
0
        public IActionResult AddEditFrameworkCompetency(int frameworkId, FrameworkCompetency frameworkCompetency, int?frameworkCompetencyGroupId, int frameworkCompetencyId = 0)
        {
            if (!ModelState.IsValid)
            {
                ModelState.Remove(nameof(FrameworkCompetency.Name));
                ModelState.AddModelError(nameof(FrameworkCompetency.Name), "Please enter a valid competency statement (between 3 and 500 characters)");
                // do something
                var detailFramework = frameworkService.GetDetailFrameworkByFrameworkId(frameworkId, GetAdminId());
                if (detailFramework == null)
                {
                    return(StatusCode(404));
                }
                var model = new FrameworkCompetencyViewModel()
                {
                    DetailFramework            = detailFramework,
                    FrameworkCompetencyGroupId = frameworkCompetencyId,
                    FrameworkCompetency        = frameworkCompetency,
                };
                return(View("Developer/Competency", model));
            }
            var adminId  = GetAdminId();
            var userRole = frameworkService.GetAdminUserRoleForFrameworkId(adminId, frameworkId);

            if (userRole < 2)
            {
                return(StatusCode(403));
            }
            if (frameworkCompetency.Id > 0)
            {
                frameworkService.UpdateFrameworkCompetency(frameworkCompetencyId, frameworkCompetency.Name, frameworkCompetency.Description, adminId);
                return(new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId, frameworkCompetencyId }) + "#fc-" + frameworkCompetencyId.ToString()));
            }
            var newCompetencyId = frameworkService.InsertCompetency(frameworkCompetency.Name, frameworkCompetency.Description, adminId);

            if (newCompetencyId > 0)
            {
                var newFrameworkCompetencyId = frameworkService.InsertFrameworkCompetency(newCompetencyId, frameworkCompetencyGroupId, adminId, frameworkId);
                return(new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId, frameworkCompetencyId }) + "#fc-" + newFrameworkCompetencyId.ToString()));
            }
            logger.LogWarning($"Attempt to add framework competency failed for admin {adminId}.");
            return(StatusCode(403));
        }