예제 #1
0
        public IActionResult Edit(StudentsEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var student = _studentRepository.GetStudentById(model.Id);
                //student.Name = model.Name; student.History = model.History;
                //student.Sex = model.Sex;
                if (model.Photos != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string uploadsFoder = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(uploadsFoder);
                    }
                    student.UrlImage = ProcessUploadedFile(model);
                }

                _studentRepository.UpdateStudent(student);
                var result = _studentRepository.Commit();

                if (result)
                {
                    TempData["Message"] = "Create Finish";
                }
                else
                {
                    TempData["Message"] = "Create Fails";
                }
                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
예제 #2
0
        public IActionResult Edit(int id)
        {
            Student Student = new Student();
            StudentsEditViewModel studentsEditViewModel = new StudentsEditViewModel
            {
                Id   = Student.StudentId,
                Name = Student.Name,
                ExistingPhotoPath = Student.UrlImage,
                Sex     = Student.Sex,
                History = Student.History,
                GroupId = Student.GroupId
            };

            studentsEditViewModel.Groups = new SelectList(groupRepository.GetGroupsAll, "GroupId", "GroupName");
            return(View(studentsEditViewModel));
        }