コード例 #1
0
        public void UpdateStudent(string studentId, StudentEditInputModel editModel)
        {
            var student = Repositories.Students.Query()
                          .AsNoTracking()
                          .SingleOrDefault(s => s.Id == studentId);

            if (student == null)
            {
                throw new TargetException("Student does not exist");
            }

            var newData = Mapper.Map <StudentEditInputModel, Student>(editModel);

            newData.Id        = studentId;
            newData.StartYear = student.StartYear;

            Repositories.Students.Update(newData);
        }
コード例 #2
0
        public async Task <IActionResult> Edit(StudentEditInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                StudentServiceModel serviceModel = model.To <StudentServiceModel>();

                bool result = await this.studentService.EditStudentAsync(serviceModel);

                if (result)
                {
                    return(this.RedirectToAction("All"));
                }
            }

            var studentClass = await this.classService.GetStudentClassDropdownAsync(model.Id);

            this.ViewBag.StudentClass = studentClass;

            return(this.View(model));
        }
コード例 #3
0
        public async Task <IActionResult> EditStudent(StudentEditInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                var serviceModel = model.To <StudentServiceModel>();

                var result = await this.studentService.EditStudentAsync(serviceModel);

                if (result)
                {
                    return(this.RedirectToAction("StudentsAll", new { id = model.ClassId }));
                }
            }

            string classFullName = await this.classService.GetClassNameByIdAsync(model.ClassId);

            string classId = model.ClassId;

            this.ViewBag.ClassName = classFullName;
            this.ViewBag.ClassId   = classId;

            return(this.View(model));
        }
コード例 #4
0
 public void Update([FromRoute] string studentId, [FromBody] StudentEditInputModel editModel)
 {
     _studentService.UpdateStudent(studentId, editModel);
 }