public static void Start() { IEnumerable <Type> ruleTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => typeof(IValidationRule).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); var db = new CADBContext(); foreach (var type in ruleTypes) { var rule = Activator.CreateInstance(type) as IValidationRule; var ruleModel = new ValidatorModel(rule); //Debug.WriteLine($"[ValidationRuleConfig.Start] Found {ruleModel}"); ValidatorModel _ruleModel = db.ValidatorModels.SingleOrDefault(x => x.FullName == ruleModel.FullName); if (_ruleModel == null) { Debug.WriteLine($"[ValidationRuleConfig.Start] Adding {ruleModel}"); db.ValidatorModels.Add(ruleModel); db.SaveChanges(); } } db.Dispose(); }
public ValidatorModel Insert(object pObj) { using (_repo = new UsuarioRepository()) { ValidatorCadastroUsuario validator = new ValidatorCadastroUsuario(); ValidatorModel resultValidator = validator.Validator((UsuarioModel)pObj); if (resultValidator.Result == true) { bool result = _repo.Insert(pObj); if (!result) { resultValidator.Mensagens.Add("Ocorreu alguma exceção, tente novamente (caso não funcione, ligue para o suporte)"); resultValidator.Result = false; return(resultValidator); } resultValidator.Mensagens.Add("Cadastro efetuado com sucesso"); return(resultValidator); } else { return(resultValidator); } } }
public ActionResult DeleteConfirmed(int id) { ValidatorModel ruleModel = db.ValidatorModels.Find(id); db.ValidatorModels.Remove(ruleModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,FullName,Description,Active,StartDate,EndDate")] ValidatorModel ruleModel) { if (ModelState.IsValid) { db.Entry(ruleModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ruleModel)); }
public static void Add <T>(this ValidatorModel validatorGroup, Expression <Func <T, object> > loginExpress = null) { if (!ValidatorCollection.TryAdd(validatorGroup.ToString().ToLower(), loginExpress == null ? typeof(T).GetGenericProperties().Select(x => x.Name).ToArray() : loginExpress.GetExpressionToArray())) { throw new Exception($"键{validatorGroup.ToString()}的表达式已经注册过了"); } }
public ActionResult Create([Bind(Include = "Id,FullName,Description,Active,StartDate,EndDate")] ValidatorModel ruleModel) { if (ModelState.IsValid) { db.ValidatorModels.Add(ruleModel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ruleModel)); }
// GET: RuleModels/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ValidatorModel ruleModel = db.ValidatorModels.Find(id); if (ruleModel == null) { return(HttpNotFound()); } return(View(ruleModel)); }
public ValidatorModel Login(UsuarioModel pModel) { ValidatorLogin validatorLogin = new ValidatorLogin(); ValidatorModel resultValidator = validatorLogin.Validator(pModel); if (resultValidator.Result == false) { return(resultValidator); } else { resultValidator.Mensagens.Add("Bem Vindo =D"); return(resultValidator); } }
public ValidatorModel Validator(UsuarioModel pModel) { ValidatorModel model = new ValidatorModel(); if (string.IsNullOrWhiteSpace(pModel.login_id)) { model.Mensagens.Add("Preencha o campo Login"); } if (string.IsNullOrWhiteSpace(pModel.senha)) { model.Mensagens.Add("Preencha o campo Senha"); } int result = svcUsuario.ExisteLogin(pModel.login_id); if (result == 2) { model.Mensagens.Add("Ocorreu alguma exceção, tente novamente (Caso não funcione, ligue para o suporte)"); } if (result == 0) { model.Mensagens.Add("Login inválido"); } if (result == 1) { UsuarioModel modelUsuario = svcUsuario.ObterPorKeyString(pModel.login_id); if (pModel.senha != modelUsuario.senha) { model.Mensagens.Add("Senha inválida"); } } if (model.Mensagens.Count > 0) { model.Result = false; } else { model.Result = true; } return(model); }
public override IEnumerable <ValidatorModel> GetMessageModels() { List <ValidatorModel> lst = new List <ValidatorModel>(); string lab = Label; if (Pattern != null) { lst.Add(MakeModel("pattern", TextProvider.Message(MessageIds.invalid_field, lab))); } switch (Type) { case CalendarTypes.PastDate: lst.Add(MakeModel("date_validation", TextProvider.Message(MessageIds.past_date_only, lab))); break; case CalendarTypes.FutureDate: lst.Add(MakeModel("date_validation", TextProvider.Message(MessageIds.future_date_only, lab))); break; case CalendarTypes.Custom: var message = new ValidatorModel(); if (Range.Message != null) { message = MakeModel("date_validation", TextProvider.Message(Range.Message)); } else if (!string.IsNullOrEmpty(Range.StartDate) && !string.IsNullOrEmpty(Range.EndDate)) { message = MakeModel("date_validation", TextProvider.Message(MessageIds.invalid_min_and_max, lab, Range.StartDate, Range.EndDate)); } else if (!string.IsNullOrEmpty(Range.StartDate)) { message = MakeModel("date_validation", TextProvider.Message(MessageIds.invalid_min, lab, Range.StartDate)); } else if (!string.IsNullOrEmpty(Range.EndDate)) { message = MakeModel("date_validation", TextProvider.Message(MessageIds.invalid_max, lab, Range.EndDate)); } lst.Add(message); break; } return(lst); }
protected void btnConfirmar_Click(object sender, EventArgs e) { //CRIAR CLASSE QUE TEM A LISTA DE ERROS E UM BOOL RESULT LimpaHiddenFields(); UsuarioModel model = new UsuarioModel() { nome = cadastroNome.Value, login_id = cadastroUsuario.Value, email = cadastroEmail.Value, senha = cadastroSenha.Value }; ValidatorModel result = svcUsuario.Insert(model); Result.Value = result.Result.ToString(); foreach (string item in result.Mensagens) { Mensagens.Value += $"{item}\n"; } DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(UsuarioModel)); MemoryStream msObj = new MemoryStream(); js.WriteObject(msObj, model); msObj.Position = 0; StreamReader sr = new StreamReader(msObj); string json = sr.ReadToEnd(); Objeto.Value = json; sr.Close(); msObj.Close(); ClientScriptManager cs = Page.ClientScript; cs.RegisterStartupScript(btnConfirmar.GetType(), "mensagem", "CadastroOk()", true); }
protected void btnEntrar_Click(object sender, EventArgs e) { LimpaHiddenFields(); UsuarioModel model = new UsuarioModel() { login_id = inputTextLogin.Value, senha = inputTextSenha.Value }; ValidatorModel result = svcUsuario.Login(model); Result.Value = result.Result.ToString(); foreach (string item in result.Mensagens) { Mensagens.Value += $"{item}\n"; } ClientScriptManager cs = Page.ClientScript; cs.RegisterStartupScript(btnConfirmar.GetType(), "mensagem", "Mensagens()", true); }
public ListElement(ValidatorModel validator, bool ignoreEmpty) : base(ignoreEmpty) => Validator = validator;
/// <summary> /// 获取方法上绑定的model校验字段 /// </summary> /// <param name="validatorGroup"></param> /// <returns></returns> public static string[] GetModelParameters(this ValidatorModel validatorGroup) { return(validatorGroup.ToString().GetModelParameters()); }
public ValidatorModel Validator(UsuarioModel pModel) { ValidatorModel model = new ValidatorModel(); //CAMPOS OBRIGATÓRIOS if (string.IsNullOrWhiteSpace(pModel.nome)) { model.Mensagens.Add("Preencha o campo Nome"); } if (string.IsNullOrWhiteSpace(pModel.login_id)) { model.Mensagens.Add("Preencha o campo Login"); } if (string.IsNullOrWhiteSpace(pModel.email)) { model.Mensagens.Add("Preencha o campo E-mail"); } if (string.IsNullOrWhiteSpace(pModel.senha)) { model.Mensagens.Add("Preencha o campo Senha"); } //VERIFICA SE LOGIN E EMAIL JÁ EXISTE NA BASE DE DADOS int resultLogin = svcUsuario.ExisteLogin(pModel.login_id); if (resultLogin == 1) { model.Mensagens.Add("Login já existe, tente outro"); } if (resultLogin == 2) { model.Mensagens.Add("Ocorreu alguma exceção, tente novamente (caso não funcione, ligue para o suporte)"); } int resultEmail = svcUsuario.ExisteEmail(pModel.email); if (resultEmail == 1) { model.Mensagens.Add("E-mail já existe, tente outro"); } if (resultEmail == 2) { model.Mensagens.Add("Ocorreu alguma exceção, tente novamente (caso não funcione, ligue para o suporte)"); } if (model.Mensagens.Count > 0) { model.Result = false; } else { model.Result = true; } return(model); }
public ObjectModelValidatorFilter(ValidatorModel validatorGroup) { MethodsParameters = validatorGroup.GetModelParameters()?.Select(x => x.ToLower())?.ToArray(); }