Exemplo n.º 1
0
 public ActionResult DetailsEdit(StudentEditModel modelStudent)
 {
     var myStudent = _studentRepository.GetById(modelStudent.Id);
     modelStudent.Tutor1 = _parentRepository.GetById(modelStudent.Tutor1.Id);
     modelStudent.Tutor2 = _parentRepository.GetById(modelStudent.Tutor2.Id);
     var studentModel = Mapper.Map<StudentEditModel, Student>(modelStudent);
     _studentRepository.UpdateStudentFromStudentEditModel(studentModel, myStudent);
     const string title = "Estudiante Actualizado";
     var content = "El estudiante " + myStudent.FullName + " ha sido actualizado exitosamente.";
     _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage);
     return RedirectToAction("Details/" + modelStudent.Id);
 }
Exemplo n.º 2
0
 public ActionResult Edit(StudentEditModel modelStudent)
 {
     var validImageTypes = new []
     {
         "image/gif",
         "image/jpeg",
         "image/pjpeg",
         "image/png"
     };
     if (modelStudent.FilePicture != null && modelStudent.FilePicture.ContentLength > 0)
     {
         if (!validImageTypes.Contains(modelStudent.FilePicture.ContentType))
         {
             ModelState.AddModelError("FilePicture", "Por favor seleccione entre una imagen GIF, JPG o PNG");
         }
     }
     var myStudent = _studentRepository.GetById(modelStudent.Id);
         try
         {
             byte[] fileBytes = null;
             if (modelStudent.FilePicture != null)
             {
                 using (var binaryReader = new BinaryReader(modelStudent.FilePicture.InputStream))
                 {
                     fileBytes = binaryReader.ReadBytes(modelStudent.FilePicture.ContentLength);
                 }
             }
             if (modelStudent.Tutor1 == null)
                 modelStudent.Tutor1 = myStudent.Tutor1;
             if (modelStudent.Tutor2 == null)
                 modelStudent.Tutor2 = myStudent.Tutor2;
             var studentModel = Mapper.Map<StudentEditModel, Student>(modelStudent);
             studentModel.MyGender = Implement.Utilities.DefineGender(modelStudent.MyGender);
             modelStudent.Photo = null;
             studentModel.Photo = fileBytes ?? myStudent.Photo;
             studentModel.MyUser = _parentRepository.GetById(modelStudent.Tutor1.Id).MyUser;
             myStudent = _studentRepository.UpdateStudentFromStudentEditModel(studentModel, myStudent);
             const string title = "Estudiante Actualizado";
             var content = "El estudiante " + myStudent.FullName + " ha sido actualizado exitosamente.";
             _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage);
             return RedirectToAction("Index");
         }
         catch
         {
             modelStudent.MyGender = myStudent.MyGender.ToString("G").Substring(0, 1);
             modelStudent.FirstParent = myStudent.Tutor1.Id;
             modelStudent.Tutor1 = myStudent.Tutor1;
             modelStudent.Tutor2 = myStudent.Tutor2;
             if (myStudent.Tutor2 != null)
                 modelStudent.SecondParent = myStudent.Tutor2.Id;
             ViewBag.Tutor1Id = new SelectList(_parentRepository.Query(x => x), "Id", "FullName",
                 modelStudent.Tutor1.Id);
             if (modelStudent.Tutor2 == null)
                 modelStudent.Tutor2 = new Parent();
             ViewBag.Tutor2Id = new SelectList(_parentRepository.Query(x => x), "Id", "FullName",
                 modelStudent.Tutor2.Id);
             return View(modelStudent);
         }
 }
Exemplo n.º 3
0
 public Student UpdateStudentFromStudentEditModel(StudentEditModel studentEditModel, Student student)
 {
     student.FirstName = studentEditModel.FirstName;
     student.LastName = studentEditModel.LastName;
     student.FullName = (studentEditModel.FirstName + " " + studentEditModel.LastName).Trim();
     student.Country = studentEditModel.Country;
     student.IdNumber = studentEditModel.IdNumber;
     student.BirthDate = studentEditModel.BirthDate;
     student.Gender = Utilities.IsMasculino(studentEditModel.Gender);
     student.Nationality = studentEditModel.Nationality;
     student.State = studentEditModel.State;
     student.City = studentEditModel.City;
     student.Address = studentEditModel.Address;
     student.Biography = studentEditModel.Biography;
     student.StartDate = studentEditModel.StartDate;
     student.BloodType = studentEditModel.BloodType;
     student.AccountNumber = studentEditModel.AccountNumber;
     student.Tutor1 = studentEditModel.FirstParent;
     student.Tutor2 = studentEditModel.SecondParent;
     return Update(student);
 }