public ActionResult ViewStudent(StudentSearchViewModel userInput) { StudentHelper helper = new StudentHelper(); string error = ""; DisplayStudentViewModel viewModel = helper.GetStudentDetails(userInput.bid, out error, true); if (viewModel != null) { ViewBag.bid = userInput.bid; return(PartialView("_ViewStudent", viewModel)); } return(Content(error)); }
/// <summary> /// Method to get the details of a student /// </summary> /// <param name="bid">the BID of the student</param> /// <param name="error">out, an error message</param> /// <param name="archive">true, if the student is in the archive false otherwise</param> /// <returns>the details of the student</returns> public DisplayStudentViewModel GetStudentDetails(string bid, out string error, bool archive = false) { error = ""; // get the student from the database Student student = GetStudent(bid, archive); // if the student exists if (student != null) { List <AllotmentDisplayViewModel> allotmentViewModel = new List <AllotmentDisplayViewModel>(); // get the student and the allotment foreach (var allotment in student.Allotments) { allotmentViewModel.Add(new AllotmentDisplayViewModel { blockNumber = allotment.hostelBlock, doj = allotment.dateOfJoin, dol = allotment.dateOfLeave.HasValue ? allotment.dateOfLeave.Value.Date + "" : "", roomNumber = allotment.roomNum, roomType = allotment.Room.RoomType1.val, floorNumber = allotment.roomNum < 100 ? 'G' : allotment.roomNum.ToString().ToCharArray()[0], year = allotment.year + " - " + (allotment.year + 1) }); } // construct the view model if (archive) { DisplayStudentViewModel viewmodel1 = new DisplayStudentViewModel() { name = student.name, gender = student.Gender1.val, branch = student.Department.val, course = student.Course1.val, dob = student.dob, semester = student.semester, usn = student.usn, allotments = allotmentViewModel, aadharNumber = student.aadhar, pan = student.pan, email = student.email, phoneNumber = student.phone.HasValue ? student.phone.Value : 0, }; return(viewmodel1); } DisplayStudentViewModel viewmodel = new DisplayStudentViewModel() { name = student.name, gender = student.Gender1.val, branch = student.Department.val, course = student.Course1.val, dob = student.dob, semester = student.semester, usn = student.usn, allotments = allotmentViewModel, year = student.Allotments.Where(x => x.dateOfLeave == null).First().year, aadharNumber = student.aadhar, pan = student.pan, email = student.email, phoneNumber = student.phone.HasValue ? student.phone.Value : 0, }; return(viewmodel); } else { error = "Student not found!"; return(null); } }