public ActionResult SubmitTest(FormCollection collection) { int correct = 0; int wrong = 0; const int unAnwsered = 0; string wrongAnwsers = ""; var username = User.Identity.Name; var mp = _examinationRepository.GetProfile(username); foreach (var key in collection.Keys) { if ((string)key != "TotalCount" && (string)key != "ExaminationId") { int value = int.Parse(collection[key.ToString()]); //int realvalue = int.Parse(collection[key..ToString()]); var op = _examinationRepository.GetExamOption(value); // var checker = _examinationRepository.GetExamAnswer(op.ExamQuestion.Id); // _db.TestOptions.Include("TestQuestion").FirstOrDefault(x => x.Id == value); //get Question var question = _examinationRepository.GetExamQuestion(op.ExamQuestion.Id); //_db.TestQuestions.Include("TestAnswer").FirstOrDefault(x => x.Id == checker.TestQuestion.Id); if (question.ExamAnswer.ExamOption.Id == op.Id) { correct++; } else { wrong++; wrongAnwsers = wrongAnwsers + Environment.NewLine + question.QuestionContent + "(" + op.OptionContent + ")" + Environment.NewLine; //add the question plus the selected anser } } } string modifiedwrongAnwsers = wrongAnwsers .Replace(Environment.NewLine, "<br />") .Replace("\r", "<br />") .Replace("\n", "<br />"); var total = collection["TotalCount"]; int ide = int.Parse(collection["ExaminationId"]); var examname = _examinationRepository.GetExaminationData(ide); double calculate = Convert.ToDouble(correct) / Convert.ToDouble(total) * 100; // var rem="The PassMark is 50 percent, and you scored " + calculate + " %"; var rem = "You scored " + Math.Round(Convert.ToDecimal(calculate), 2) + " %"; string stat; string storeStat; if (calculate >= 50) { stat = "Congratulations,youv passed our Evaluation.The Human Resource Team will get in touch with you shortly"; //storeStat = "Passed"; storeStat = calculate.ToString(CultureInfo.InvariantCulture); //send a mail to admin //create the message here var writer = new StringWriter(); var html = new HtmlTextWriter(writer); html.RenderBeginTag(HtmlTextWriterTag.H1); html.WriteEncodedText("Evaluation Result"); html.RenderEndTag(); html.WriteEncodedText("Dear Admin "); html.WriteBreak(); html.RenderBeginTag(HtmlTextWriterTag.P); html.WriteEncodedText("THIS IS TO INFORM YOU THAT A USER HAS TAKEN A TEST AND PASSED.FIND THE DETAILS BELOW :"); html.WriteBreak(); html.WriteEncodedText("USERNAME : "******"FULL NAME : " + mp.FullName); html.WriteBreak(); html.WriteEncodedText("TEST NAME : " + examname.Name); html.WriteBreak(); html.WriteEncodedText("SCORE : " + calculate); html.WriteBreak(); html.WriteEncodedText("Wrong Answers : " + modifiedwrongAnwsers); html.WriteBreak(); html.WriteBreak(); html.WriteBreak(); html.WriteEncodedText("REGARDS"); html.WriteBreak(); html.WriteEncodedText("RASMED PUBLICATIONS HR TEAM "); html.WriteBreak(); html.RenderEndTag(); html.Flush(); string htmlString = writer.ToString(); var msg = new MailModel { From = "*****@*****.**", To = "*****@*****.**", Bcc = "*****@*****.**", Name = "Administrator", Message = htmlString, Subject = "Rasmed Publications Evaluation Result" }; _mailPusher.SendEmail(msg.To, msg.Name, msg.Bcc, msg.Subject, msg.Message); } else { stat = "Sorry, You failed.Please check back in the next 24 hours for a retake if the exam permits multiple attempst"; storeStat = calculate.ToString(CultureInfo.InvariantCulture); } _examinationRepository.ComputeResult(mp.Member.Id, correct, wrong, unAnwsered, modifiedwrongAnwsers, DateTime.Now, storeStat); var test = new Testresultvm { Correct = correct.ToString(), Wrong = wrong.ToString(), Outcome = rem, Remark = stat, RemainingAttempt = _examinationRepository.NumberOfRemainingAttempt(mp.Member.UserName, examname.Id) }; return(RedirectToAction("TestResult", test)); }