コード例 #1
0
ファイル: Create.cshtml.cs プロジェクト: vector8/MentoringApp
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Student.Add(Student);
            await _context.SaveChangesAsync();

            var questions = await _context.Question.ToListAsync();

            foreach (Question q in questions)
            {
                Answer a = new Answer();
                a.AnswerText = String.Format("{0}", Request.Form[q.QuestionText]);
                a.StudentFk  = Student;
                a.QuestionFk = q;

                _context.Answer.Add(a);
            }

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
ファイル: Create.cshtml.cs プロジェクト: vector8/MentoringApp
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Question.Add(Question);

            var students = await _context.Student.ToListAsync();

            foreach (Student s in students)
            {
                Answer a = new Answer();
                a.QuestionFk = Question;
                a.StudentFk  = s;
                a.AnswerText = "";

                _context.Answer.Add(a);
            }

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Question).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionExists(Question.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            _context.Database.ExecuteSqlCommand("delete from Answer");
            _context.Database.ExecuteSqlCommand("delete from Student");
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
ファイル: Index.cshtml.cs プロジェクト: vector8/MentoringApp
        public async Task OnGetAsync()
        {
            question = await _context.Question.ToListAsync();

            var settingsList = await _context.Settings.ToListAsync();

            if (settingsList.Count == 0)
            {
                settings = new Settings();
                settings.facultyWeight = 0.5f;
                settings.programWeight = 0.5f;
                _context.Settings.Add(settings);
                await _context.SaveChangesAsync();
            }
            else
            {
                settings = settingsList[0];
            }
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            var matches = await _context.Match.ToListAsync();

            var students = await _context.Student.ToListAsync();

            foreach (var s in students)
            {
                s.Match = null;
            }
            foreach (var m in matches)
            {
                _context.Match.Remove(m);
            }
            //_context.Database.ExecuteSqlCommand("update Student set MatchID = NULL");
            //_context.Database.ExecuteSqlCommand("delete from Match");
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #7
0
ファイル: Delete.cshtml.cs プロジェクト: vector8/MentoringApp
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Question = await _context.Question.FindAsync(id);

            if (Question != null)
            {
                var answers = await _context.Answer.Where(a => a.QuestionFk.ID == Question.ID).ToListAsync();

                _context.Answer.RemoveRange(answers);

                _context.Question.Remove(Question);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #8
0
ファイル: Delete.cshtml.cs プロジェクト: vector8/MentoringApp
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Student = await _context.Student.FindAsync(id);

            if (Student != null)
            {
                var answers = await _context.Answer.Where(a => a.StudentFk.ID == id).ToListAsync();

                _context.Answer.RemoveRange(answers);

                _context.Student.Remove(Student);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #9
0
        public async Task <IActionResult> OnPostAsync()
        {
            var question = await _context.Question.ToListAsync();

            var settingsList = await _context.Settings.ToListAsync();

            Settings settings;

            if (settingsList.Count == 0)
            {
                settings = new Settings();
                settings.facultyWeight = 0.5f;
                settings.programWeight = 0.5f;
                _context.Settings.Add(settings);
                await _context.SaveChangesAsync();
            }
            else
            {
                settings = settingsList[0];
            }

            return(RedirectToPage("./Matches"));
        }
コード例 #10
0
ファイル: Edit.cshtml.cs プロジェクト: vector8/MentoringApp
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Student).State = EntityState.Modified;

            Question = await _context.Question.ToListAsync();

            foreach (Question q in Question)
            {
                var answer = await _context.Answer.Where(a => a.StudentFk.ID == Student.ID && a.QuestionFk.ID == q.ID).SingleOrDefaultAsync();

                answer.AnswerText = String.Format("{0}", Request.Form[q.QuestionText]);
                _context.Answer.Update(answer);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(Student.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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