public ActionResult StartTest(int examId) { var me = _examinationRepository.GetProfile(User.Identity.Name); var checker = _examinationRepository.GetExaminationData(examId); if (checker.Members.Contains(me.Member) && checker.Active) { int count = _examinationRepository.NumberOfRemainingAttempt(User.Identity.Name, checker.Id); if (count < 1) { return(View("AttemptExhausted")); } if (_examinationRepository.CheckedIfPassed(me.Member.Id, checker)) { //tell user he has passed and do not need to take test return(View("AlreadyPassed")); } if (_examinationRepository.OngoingTest(me.Member.Id)) { //tell him he's presently taking a test he has not finished or it's less than 24hours he took a failed test return(View("OnGoingTest")); } _examinationRepository.SaveExamCount(checker.Id, me.Member.Id); var endTime = _examinationRepository.InitiateTest(me.Member.Id, checker); TimeSpan diff = DateTime.Parse(endTime) - DateTime.Now; ViewBag.EndtimeSeconds = Convert.ToInt32(diff.TotalSeconds); ViewBag.EndtimeMilliSeconds = Convert.ToInt32(diff.TotalMilliseconds); ViewBag.EndtimeMinutes = Convert.ToInt32(diff.TotalMinutes) - 1; ViewBag.ExaminationId = checker.Id; var allQuestion = _examinationRepository.LoadQuestions(checker.Id); return(View(allQuestion)); } return(View("InvalidAccess")); }