// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedGroups)
        {
            var newQuestionnaire = new Questionnaire();

            if (selectedGroups != null)
            {
                newQuestionnaire.Targets = new List <QuestionnaireGroup>();
                foreach (var group in selectedGroups)
                {
                    var groupToAdd = new QuestionnaireGroup
                    {
                        GroupID = int.Parse(group)
                    };
                    newQuestionnaire.Targets.Add(groupToAdd);
                }
            }

            if (await TryUpdateModelAsync <Questionnaire>(
                    newQuestionnaire,
                    "Questionnaire",
                    q => q.Title, q => q.Description,
                    q => q.DueDate, q => q.Questions, q => q.Targets))
            {
                _context.Questionnaires.Add(newQuestionnaire);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            PopulateAssignedQuestionnaireGroupData(_context, newQuestionnaire);

            return(Page());
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync(string[] selectedUsers)
        {
            var newGroup = new Group();

            if (selectedUsers != null)
            {
                newGroup.UserGroups = new List <UserGroup>();
                foreach (var user in selectedUsers)
                {
                    var userToAdd = new UserGroup
                    {
                        UserID = user
                    };
                    newGroup.UserGroups.Add(userToAdd);
                }
            }

            if (await TryUpdateModelAsync <Group>(
                    newGroup,
                    "Group",
                    i => i.Name))
            {
                _context.Groups.Add(newGroup);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            PopulateAssignedUserData(_context, newGroup);
            return(Page());
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedUsers)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var groupToUpdate = await _context.Groups
                                .Include(g => g.UserGroups)
                                .FirstOrDefaultAsync(g => g.ID == id);

            if (groupToUpdate == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync <Group>(
                    groupToUpdate,
                    "Group",
                    i => i.Name))
            {
                UpdateGroupUsers(_context, selectedUsers, groupToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            UpdateGroupUsers(_context, selectedUsers, groupToUpdate);
            PopulateAssignedUserData(_context, groupToUpdate);
            return(Page());
        }
Beispiel #4
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedGroups)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var questionnaireToUpdate = await _context.Questionnaires
                                        .Include(q => q.Targets)
                                        .Include(q => q.Questions)
                                        .ThenInclude(q => q.Answers)
                                        .FirstOrDefaultAsync(q => q.ID == id);

            if (questionnaireToUpdate == null)
            {
                return(NotFound());
            }

            // remove useranswers for answers from questionnaire that is edited
            var questionnaireUserAnswerIDsList = await _context.UserAnswers.ToListAsync();

            foreach (var q in Questionnaire.Questions)
            {
                foreach (var a in q.Answers)
                {
                    foreach (var ua in questionnaireUserAnswerIDsList)
                    {
                        if (ua.AnswerID == a.ID)
                        {
                            _context.Remove(ua);
                        }
                    }
                }
            }

            if (await TryUpdateModelAsync <Questionnaire>(
                    questionnaireToUpdate,
                    "Questionnaire",
                    q => q.Title, q => q.Description,
                    q => q.DueDate, q => q.Targets,
                    q => q.Questions))
            {
                UpdateQuestionnaireTargets(_context, selectedGroups, questionnaireToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            UpdateQuestionnaireTargets(_context, selectedGroups, questionnaireToUpdate);
            PopulateAssignedQuestionnaireGroupData(_context, questionnaireToUpdate);
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Group = await _context.Groups.FindAsync(id);

            if (Group != null)
            {
                _context.Groups.Remove(Group);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Questionnaire = await _context.Questionnaires.FindAsync(id);

            if (Questionnaire != null)
            {
                _context.Questionnaires.Remove(Questionnaire);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #7
0
        public async Task <IActionResult> OnPostAsync(int?id, List <string> selectedAnswers, string r0, string r1, string r2, string r3, string r4, string r5, string r6, string r7, string r8, string r9)
        {
            if (id == null)
            {
                return(NotFound());
            }
            selectedAnswers.Add(r0);
            selectedAnswers.Add(r1);
            selectedAnswers.Add(r2);
            selectedAnswers.Add(r3);
            selectedAnswers.Add(r4);
            selectedAnswers.Add(r5);
            selectedAnswers.Add(r6);
            selectedAnswers.Add(r7);
            selectedAnswers.Add(r8);
            selectedAnswers.Add(r9);

            var questionnaireToUpdate = await _context.Questionnaires
                                        .Include(q => q.Questions)
                                        .ThenInclude(q => q.Answers)
                                        .ThenInclude(q => q.AnswerUsers)
                                        .FirstOrDefaultAsync(q => q.ID == id);

            if (questionnaireToUpdate == null)
            {
                return(NotFound());
            }

            //if (await TryUpdateModelAsync<Questionnaire>(
            //    questionnaireToUpdate,
            //    "Questionnaire",
            //    q => q.Questions))
            if (selectedAnswers != null)
            {
                await UpdateUserAnswers(_context, selectedAnswers, questionnaireToUpdate, _userManager);

                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            await UpdateUserAnswers(_context, selectedAnswers, questionnaireToUpdate, _userManager);
            await PopulateSelectedAnswerData(questionnaireToUpdate, _userManager);

            return(Page());
        }