public async Task <ActionResult> ChoiceGridViewPartialAddNew(NorthOps.Ops.Models.Choice item, System.Nullable <Guid> ExamId) { var model = new object[0]; if (ModelState.IsValid) { try { item.ChoiceId = Guid.NewGuid(); unitOfWork.ChoiceRepo.Insert(item); await unitOfWork.SaveAsync(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } ViewBag.QuestionId = item.QuestionId; ViewBag.ExamId = ExamId; return(PartialView("_ChoiceGridViewPartial", unitOfWork.ChoiceRepo.Get(filter: m => m.QuestionId == item.QuestionId))); }
private async Task MBTI(Question question, Choice choice) { var col = question.Number % 7; var mbti = unitOfWork.PersonalityResult.Get(filter: m => m.UserId == UserId).FirstOrDefault(); if (mbti == null) { mbti = new PersonalityResult() { UserId = UserId, PersonalityResultId = Guid.NewGuid(), DateTaken = DateTime.Now }; unitOfWork.PersonalityResult.Insert(mbti); await unitOfWork.SaveAsync(); } switch (col) { case 1: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.E = (mbti.E ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.I = (mbti.I ?? 0) + 1; break; } break; case 2: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.S = (mbti.S ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.N = (mbti.N ?? 0) + 1; break; } break; case 3: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.S = (mbti.S ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.N = (mbti.N ?? 0) + 1; break; } break; case 4: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.T = (mbti.T ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.F = (mbti.F ?? 0) + 1; break; } break; case 5: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.T = (mbti.T ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.F = (mbti.F ?? 0) + 1; break; } break; case 6: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.J = (mbti.J ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.P = (mbti.P ?? 0) + 1; break; } break; default: switch (choice.ChoiceLetter.ToLower()) { case "a": mbti.UserId = UserId; mbti.J = (mbti.J ?? 0) + 1; break; default: mbti.UserId = UserId; mbti.P = (mbti.P ?? 0) + 1; break; } break; } unitOfWork.PersonalityResult.Update(mbti); await unitOfWork.SaveAsync(); }