public ActionResult ValidateTest(Guid testId) { if (Session["usercookie"] == null) { return(RedirectToAction("Authenticate", "Users")); } else { using (DBEntities dbcontext = new DBEntities()) { var pendingItems = dbcontext.StudentTestLog.Where(s => s.TestId == testId && s.MultiLineAnswer != null).ToList(); List <ValidateTest> items = new List <ValidateTest>(); foreach (StudentTestLog log in pendingItems) { ValidateTest question = new ValidateTest(); question.UserId = log.UserId; question.TestId = testId; question.Question = dbcontext.Questions.Where(q => q.QId == log.QId).Select(s => s.Question).FirstOrDefault().ToString(); question.MultiLineAnswer = log.MultiLineAnswer; question.QId = log.QId; question.Score = dbcontext.Scores.Where(s => s.QId == log.QId && s.TestId == log.TestId).Select(s => s.Score).FirstOrDefault(); items.Add(question); } return(View(items.ToList())); } } }
private void RefreshValidator() { this.messagePop.Reset(); string notEmpty = " " + ValidatorResource.NotEmpty; if (this.currentItem.BRANCH_CODE.Equals("")) { this.messagePop.SetError(AssCommonResource.BranchID + notEmpty); } if (this.currentItem.BRANCH_NAME.Equals("")) { this.messagePop.SetError(AssCommonResource.BranchName + notEmpty); } if (this.currentItem.REGION_ID == null || this.currentItem.REGION_ID.Equals("")) { this.messagePop.SetError(AssCommonResource.RegionID + notEmpty); } if (!this.currentItem.TEL.Equals("") && (!ValidateTest.IsPhoneNumber(this.currentItem.TEL) || this.currentItem.TEL.Length < 7)) { this.messagePop.SetError(AssCommonResource.Tel + " " + ValidatorResource.lblNotTrue); } if (this.currentItem.BRANCH_TYPE != null && !this.currentItem.BRANCH_TYPE.Equals("HS") && this.currentItem.FATHER_ID == "") { this.messagePop.SetError(AssCommonResource.FatherID + notEmpty); } }
private void RefreshValidator() { this.messagePop.Reset(); string notEmpty = " " + ValidatorResource.NotEmpty; if (this.currentItem.DEP_CODE.Equals("")) { this.messagePop.SetError(AssCommonResource.Dep_Code + notEmpty); } if (this.currentItem.DEP_NAME.Equals("")) { this.messagePop.SetError(AssCommonResource.Dep_Name + notEmpty); } if (this.branchName == null || this.branchName.Equals("")) { this.messagePop.SetError(AssCommonResource.BranchID + notEmpty); } if (this.currentItem.GROUP_ID == null || this.currentItem.GROUP_ID.Equals("")) { this.messagePop.SetError(AssCommonResource.GroupDep + notEmpty); } if (!this.currentItem.TEL.Equals("") && (!ValidateTest.IsPhoneNumber(this.currentItem.TEL) || this.currentItem.TEL.Length < 7)) { this.messagePop.SetError(AssCommonResource.Tel + " " + ValidatorResource.lblNotTrue); } }
public void RulesException_validation_converts_successfully() { var options = new DbContextOptionsBuilder <ValidateTestContext>() .UseInMemoryDatabase("RulesException") .Options; // Run the test against one instance of the context using (var context = new ValidateTestContext(options)) { var validateTestRepository = new ValidateTestRepository(context); var validateTestService = new ValidateTestService(validateTestRepository); var validateTest = new ValidateTest { StringProperty = String.Empty, DecimalProperty = 2M, ValidateTestArrayItems = { new ValidateTestArrayItem(), new ValidateTestArrayItem() } }; Assert.Throws <RulesException <ValidateTest> >( () => { try { validateTestService.ValidateModel(validateTest); } catch (RulesException <ValidateTest> ex) { var rulesExceptionDto = new RulesExceptionDto(ex); System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(rulesExceptionDto, Formatting.Indented)); var errorDict = ex.GetErrorDictionary(); Assert.Equal(2, errorDict.Count); Assert.True(errorDict.ContainsKey("DecimalProperty")); Assert.True(errorDict.ContainsKey("StringProperty")); Assert.Equal(2, ex.Errors.Count); throw; } }); } }
public JsonResult Validate(ValidateTest score) { if (Session["usercookie"] == null) { return(Json(new { success = false, responseText = "Please Login again" }, JsonRequestBehavior.AllowGet)); } else { using (DBEntities dbcontext = new DBEntities()) { var duplicate = dbcontext.Scores.Where(s => s.TestId == score.TestId && s.QId == score.QId).ToList(); if (duplicate.Count > 0) { foreach (Scores delete in duplicate) { dbcontext.Scores.Remove(delete); dbcontext.SaveChanges(); } } Scores log = new Scores(); log.UserId = score.UserId; log.TestId = score.TestId; log.QId = score.QId; log.Score = score.Score; log.LastUpdatedDate = DateTime.UtcNow; dbcontext.Scores.Add(log); dbcontext.SaveChanges(); StudentTestLog updateLog = dbcontext.StudentTestLog.Where(s => s.TestId == score.TestId && s.QId == score.QId).FirstOrDefault(); updateLog.isCorrected = true; dbcontext.SaveChanges(); return(Json(new { success = true, responseText = "Updated Score for User Id " + log.UserId + " with score " + log.Score + " for QId " + log.QId }, JsonRequestBehavior.AllowGet)); } } }
private void RefreshValidator() { this.messagePop.Reset(); string notEmpty = " " + ValidatorResource.NotEmpty; if (!this.isFromFile) { //if (!this.ExistUser) //{ // this.messagePop.SetError(SystemRoleResource.ExistUser); // return; //} //if (this.tlName.Equals("")) // this.messagePop.SetError(SystemRoleResource.lblUsername + notEmpty); //if (this.currentUser.Password.Equals("")) // this.messagePop.SetError(SystemRoleResource.Password + notEmpty); //if (this.currentUser.TLSUBBRID == null || this.currentUser.TLSUBBRID.Equals("")) // this.messagePop.SetError(SystemRoleResource.Branch + notEmpty); if (this.currentUser.TLFullName == null || this.currentUser.TLFullName.Equals("")) { this.messagePop.SetError(SystemRoleResource.TLFullName + notEmpty); } if (this.curBranchId == "" || this.curBranchId == null) { this.messagePop.SetSingleError(SystemRoleResource.TLSUBBRID + notEmpty); } if (this.currentUser.EMAIL == null || this.currentUser.EMAIL.Equals("")) { this.messagePop.SetError(SystemRoleResource.EMAIL + notEmpty); } else if (!ValidateTest.IsEmail(this.currentUser.EMAIL)) { this.messagePop.SetError(SystemRoleResource.EMAIL + " " + ValidatorResource.ErrorFormat); } if (this.currentUser.RoleName == null || this.currentUser.RoleName.Equals("")) { this.messagePop.SetError(SystemRoleResource.lblRole + notEmpty); } if (this.isCheckedStatus == -1) { this.isUpdate = true; this.CheckUserName(); this.messagePop.SetError("Kiểm tra username?"); } else if (this.isCheckedStatus == 0) { this.messagePop.SetError("Username không tồn tại."); } //if (this.currentUser.PHONE == null || this.currentUser.PHONE.Equals("")) // this.messagePop.SetError(SystemRoleResource.PHONE + notEmpty); //else if (!this.currentUser.PHONE.Equals("") && !ValidateTest.IsNumber(this.currentUser.PHONE)) // this.messagePop.SetError(SystemRoleResource.PHONE + " " + ValidatorResource.ErrorFormat); } else { if (this.FileName == null || this.FileName.Equals("")) { this.messagePop.SetError(SystemRoleResource.lblFile + notEmpty); } if (this.roleName == null || this.roleName.Equals("")) { this.messagePop.SetError(SystemRoleResource.lblRole + notEmpty); } } }