コード例 #1
0
        public async Task <IActionResult> AddParents(EditParentsInputModel model)
        {
            model.StudentId = await CheckStudentId(this.TempData["studentId"]);

            await this.studentsService.AddParents(model);

            return(await Task.Run(() => this.RedirectToAction("Details", new { studentId = model.StudentId })));
        }
コード例 #2
0
        public async Task <IActionResult> AddParents()
        {
            int studentId = await CheckStudentId(this.TempData["studentId"]);

            var parents = this.parentsService.GetAllForSelection(studentId).ToList();
            var model   = new EditParentsInputModel()
            {
                Parents = parents
            };

            this.TempData.Keep("studentId");

            return(await Task.Run(() => this.View("AddParents", model)));
        }
コード例 #3
0
        public async Task AddParents(EditParentsInputModel model)
        {
            var student = await this.db.Students.FirstOrDefaultAsync(x => x.Id == model.StudentId);

            var parentIds         = model.Parents.Where(x => x.Selected).Select(x => x.Id).ToArray();
            var parentsForStudent = this.db.Parents.Where(x => parentIds.Contains(x.Id)).ToArray();

            foreach (var parent in parentsForStudent)
            {
                var link = new StudentParent {
                    ParentId = parent.Id
                };
                student.Parents.Add(link);
            }

            await this.db.SaveChangesAsync();
        }