private EntityValidationDTO ToEntityValidationDTO(EntityValidation item, bool withDetails) { EntityValidationDTO result = new EntityValidationDTO(); result.FormulaID = item.FormulaID ?? 0; if (result.FormulaID != 0 && withDetails) { //??با جزئیات؟؟........................................................................ var bizFormula = new BizFormula(); //result.Formula = bizFormula.GetFormula(item.FormulaID.Value,false); } //result.CodeFunctionID = item.CodeFunctionID ?? 0; //if (result.CodeFunctionID != 0 && withDetails) //{ // var bizCodeFunction = new BizCodeFunction(); // result.CodeFunction = bizCodeFunction.GetCodeFunction(item.CodeFunctionID.Value); //} result.TableDrivedEntityID = item.TableDrivedEntityID; result.ID = item.ID; result.Message = item.Message; result.Title = item.Title; // result.ResultSensetive = item.ResultSensetive; //result.Value = item.Value; return(result); }
public void Add(Seguro entity) { var fiscal = new EntityValidation(entity); if (!fiscal.Valid()) { throw new Exception(fiscal.GetErrorMessage()); } using (Context context = new Context()) { context.Seguros.Add(entity); context.Save(); } }
public void Update(Seguro entity) { var fiscal = new EntityValidation(entity); if (!fiscal.Valid()) { throw new Exception(fiscal.GetErrorMessage()); } using (Context context = new Context()) { entity.ProdutoTipoId = entity.ProdutoTipo.Id; context.Produtos.Update(entity.Produto); context.Seguros.Update(entity); context.Save(); } }
public void AddValidation(EntityValidation <TEntity> validationExpression, string propertyName = null) { if (propertyName == null) { _validationExpressions.Add(validationExpression); return; } if (typeof(TEntity).GetRuntimeProperties().All(p => p.Name != propertyName)) { throw new ArgumentException($"No property \"{propertyName}\" found on type \"{typeof(TEntity).Name}\""); } if (!_properties.ContainsKey(propertyName)) { _properties.Add(propertyName, new EntityPropertyValidationMap <TEntity>(propertyName)); } _properties[propertyName].AddValidation(validationExpression); }
public static void SetValidationAnnotation <TEntity>( this EdmModel model, IEdmTerm term, IEdmExpression expression, string message, Expression <Func <TEntity, bool> > validationExpression = null, Expression <Func <TEntity, object> > propertyExpression = null) { if (model == null) { throw new ArgumentNullException(nameof(model)); } // TODO: If validation expression is null, then compile it from the IQL var type = model.GetEdmType(typeof(TEntity)) as EdmEntityType; IEdmVocabularyAnnotatable target = type; string propertyName = null; if (propertyExpression != null) { propertyName = propertyExpression.GetAccessedProperty().Name; var property = type.Properties().Single(p => p.Name == propertyName); target = property; } IqlQueryableAdapter.ExpressionConverter = () => new ExpressionToIqlConverter(); //var iql = ExpressionToIqlExpressionParser<TEntity>.Parse(validationExpression); //var parser = // new ActionParserInstance<ODataIqlData, ODataIqlExpressionAdapter>(new ODataIqlExpressionAdapter()); var expressionLabel = new EdmLabeledExpression("Expression", expression); var messageLabel = new EdmLabeledExpression("Message", new EdmStringConstant(message)); var coll = new EdmCollectionExpression(expressionLabel, messageLabel); var annotation = new EdmVocabularyAnnotation(target, term, coll); var validation = ValidationMap.ForModel(model); var validationObject = new EntityValidation <TEntity>(validationExpression, message); validation.EntityValidation <TEntity>() .AddValidation(validationObject, propertyName); annotation.SetSerializationLocation(model, target.ToSerializationLocation()); model.AddVocabularyAnnotation(annotation); }
public bool Update(User Entity, out string state) { if (EntityValidation.ValidateUserEntity(Entity, out state)) { db.Entry(db.Users.Find(Entity.UserID)).CurrentValues.SetValues(Entity); bool sonuc = db.SaveChanges() > 1; if (sonuc) { state = "User updated successfully"; return(true); } else { return(false); } } else { return(false); } }
public bool Delete(User Entity, out string state) { if (EntityValidation.ValidateUserEntity(Entity, out state)) { Entity.IsDeleted = true; bool sonuc = db.SaveChanges() > 1; if (sonuc) { state = "User deleted successfully"; return(true); } else { return(false); } } else { return(false); } }
public bool Insert(User Entity, out string state) { if (EntityValidation.ValidateUserEntity(Entity, out state)) { db.Users.Add(Entity); bool sonuc = db.SaveChanges() > 0; if (sonuc) { state = "User added successfully"; return(true); } else { state = "There was a problem adding user to db"; return(false); } } else { return(false); } }
public bool IsSatisfiedBy(Seguro entity) { var valid = true; if (string.IsNullOrEmpty(entity.Cpf) || (entity.Cpf.Length != 11 && entity.Cpf.Length != 14)) { ErrorMessages.Add("Campo CPF/CNPJ não contem um documento válido"); valid = false; } if (entity.Cpf.Length == 11) { if (!EntityValidation.IsCpf(entity.Cpf)) { ErrorMessages.Add("CPF do seguro é inválido"); valid = false; } } if (entity.Cpf.Length == 14) { if (!EntityValidation.IsCnpj(entity.Cpf)) { ErrorMessages.Add("CNPJ do seguro é inválido"); valid = false; } } if (entity.ProdutoTipo == null) { ErrorMessages.Add("Tipo do seguro precisa ser preenchido"); valid = false; } if (entity.ProdutoTipo.Id == (int)ProdutoTipoEnum.Vida) { if (!EntityValidation.IsCpf(entity.Produto.Descricao)) { ErrorMessages.Add("CPF do segurado é inválido"); valid = false; } } if (entity.ProdutoTipo.Id == (int)ProdutoTipoEnum.Automovel) { if (entity.Produto.Descricao.Length == 7) { entity.Produto.Descricao = $"{entity.Produto.Descricao.Substring(0, 3)}-{entity.Produto.Descricao.Substring(3)}"; } if (!EntityValidation.IsPlaca(entity.Produto.Descricao)) { ErrorMessages.Add("Placa do veículo inválido"); valid = false; } } if (entity.ProdutoTipo.Id == (int)ProdutoTipoEnum.Residencial) { if (string.IsNullOrEmpty(entity.Produto.Descricao)) { ErrorMessages.Add("Endereço vazio"); valid = false; } } return(valid); }
public void AddValidation(EntityValidation <TEntity> validationExpression) { _validationExpressions.Add(validationExpression); }
public static IServiceCollection AddEntityValidation <TEntity>(this IServiceCollection services, Func <object, ValidationResult> checkFunc) where TEntity : BaseEntity { EntityValidation.SetProcessRoutines(typeof(TEntity), checkFunc); return(services); }
public EntityService() { _entityRepository = new EntityRepository(); _modelValidation = new EntityValidation(); }