public ActionResult Create(SubmissionVeiwModel model) { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(model.Answer); var count = db.Questions.ToList().Count; var correctcount = 0; model.Questions = db.Questions.ToList(); foreach (var kv in dict) { if (db.Questions.Find(Convert.ToInt64(kv.Key)).Answer.ToString() == kv.Value.ToString()) { correctcount = correctcount + 1; } } Submittion submittion = new Submittion(); if (ModelState.IsValid) { var blast = Math.Round((((double)correctcount / count) * 100), 2); submittion.Result = blast.ToString() + "%"; submittion.SubmittedOn = DateTime.Now; submittion.SubmittedAnswer = model.Answer; submittion.SubmittedBy = User.Identity.Name; db.Submittions.Add(submittion); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
// GET: Submittions/Create public ActionResult Create() { var model = new SubmissionVeiwModel(); model.Questions = db.Questions.ToList(); return(View(model)); }