private static StudentViewModel MapStudentToStudentViewModel(Student student) { var studViewModel = new StudentViewModel { Address = student.Address, DateOfBirth = student.DateOfBirth, FirstName = student.FirstName, Gender = student.Gender, Id = student.Id, LastName = student.LastName, Photo = student.Photo, PhotoContentType = student.PhotoContentType, StudentStatus = student.StudentStatus, Email = student.Email }; return studViewModel; }
private Student MapStudentViewModelToStudent(StudentViewModel studentViewModel, HttpPostedFileBase studentPhoto) { var student = _studentRepository.GetById(studentViewModel.Id); //for editing existing student if (student != null) { student.Address = studentViewModel.Address; student.DateOfBirth = studentViewModel.DateOfBirth; student.FirstName = studentViewModel.FirstName; student.Gender = studentViewModel.Gender; student.LastName = studentViewModel.LastName; student.StudentStatus = studentViewModel.StudentStatus; student.Email = studentViewModel.Email; } else // for creating new student { student = new Student { Address = studentViewModel.Address, DateOfBirth = studentViewModel.DateOfBirth, FirstName = studentViewModel.FirstName, Gender = studentViewModel.Gender, Id = studentViewModel.Id, LastName = studentViewModel.LastName, StudentStatus = studentViewModel.StudentStatus, Email = studentViewModel.Email }; } if (studentPhoto != null && studentPhoto.ContentLength > 0) { student.Photo = new byte[studentPhoto.ContentLength]; studentPhoto.InputStream.Read(student.Photo, 0, studentPhoto.ContentLength); student.PhotoContentType = studentPhoto.ContentType; } return student; }
private static Student MapStudentViewModelToStudent(StudentViewModel studentViewModel) { var studViewModel = new Student { Address = studentViewModel.Address, DateOfBirth = studentViewModel.DateOfBirth, FirstName = studentViewModel.FirstName, Gender = studentViewModel.Gender, Id = studentViewModel.Id, LastName = studentViewModel.LastName, Photo = studentViewModel.Photo, StudentStatus = studentViewModel.StudentStatus, Email = studentViewModel.Email }; return studViewModel; }