Exemplo n.º 1
0
        public IActionResult Edit(StudentEditVidewModel model)
        {
            //检查提供的数据是否有效,如果没有通过验证,需要重新编辑学生信息
            //这样用户就可以更正并重新提交编辑表单
            if (ModelState.IsValid)
            {
                Student student = _studentRepository.GetStudent(model.Id);
                student.Email     = model.Email;
                student.Name      = model.Name;
                student.ClassName = model.ClassName;

                if (model.Photos.Count > 0)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePahth = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);

                        System.IO.File.Delete(filePahth);
                    }

                    student.PhotoPath = ProcessUploadedFile(model);
                }



                Student updateStudent = _studentRepository.Update(student);


                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ViewResult Edit(int id)
        {
            Student student = _studentRepository.GetStudent(id);
            StudentEditVidewModel studentEditVidew = new StudentEditVidewModel
            {
                Id                = student.Id,
                Name              = student.Name,
                Email             = student.Email,
                ClassName         = student.ClassName,
                ExistingPhotoPath = student.PhotoPath
            };

            return(View(studentEditVidew));
        }
Exemplo n.º 3
0
        public ViewResult Edit(int id)
        {
            Student student = _studentRepository.GetStudent(id);


            StudentEditVidewModel studentEditVidew = new StudentEditVidewModel
            {
                Id                = student.id,
                Name              = student.Name,
                Email             = student.Email,
                ClassName         = student.ClassName,
                ExistingPhotoPath = student.PhptoPath
            };

            return(View(studentEditVidew));

            //   throw new Exception("查询不到这个学生信息");
        }