/// <summary> /// Method to add a cooking instruction to the database if valid /// </summary> /// <param name="name">The name of the instruction</param> /// <param name="instruction">The cooking instructions</param> /// <returns></returns> public async Task AddCookingInstructionAsync(TextBox name, TextBox instruction) { var isNameValid = ValidationObject.ValidateInstructionName(name); var isInstructionValid = ValidationObject.ValidateInstruction(instruction); var added = true; if (isNameValid && isInstructionValid) { var cookingInstructionToAdd = new CookingInstructionDTO() { Name = name.Text, Instruction = instruction.Text }; added = await Task.Run(() => BusinessObject.AddCookingInstructionAsync(cookingInstructionToAdd)); if (added) { ShowMessage($"Cooking Instruction {cookingInstructionToAdd.Name} Added"); name.Clear(); instruction.Clear(); } else { ShowMessage($"Cooking Instruction {cookingInstructionToAdd.Name} Not Added"); } } }
public async override Task Invoke(AspectContext context, AspectDelegate next) { var currentUser = context.ServiceProvider.GetService <ICurrentUser>(); ValidationObject.Validate(!currentUser.HasPermission(Code), "没有访问权限"); await next(context); }
public void ResetPassword(ResetPasswordInputDto input) { ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password), "密码不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password2), "确认密码不能为空"); ValidationObject.Validate(input.Password != input.Password2, "密码和确认密码不一致"); _repository.ResetPassword(input); }
public void ResetPassword(ResetPasswordInputDto input) { ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password), "密码不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password2), "确认密码不能为空"); ValidationObject.Validate(input.Password != input.Password2, "密码和确认密码不一致"); var entity = _userRepository.Find(input.Id); entity.PasswordHash = input.Password; }
public void Add(AddInputDto input) { ValidationObject.Validate(string.IsNullOrWhiteSpace(input.LoginName), "登录名不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password), "密码不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password2), "确认密码不能为空"); ValidationObject.Validate(input.Password != input.Password2, "密码和确认密码不一致"); ValidationObject.Validate(_repository.ExistUser(input.LoginName), "登录名已存在"); _repository.Add(input); }
public void Validate() { ValidationObject.Validate(this.Id == Guid.Empty, "id不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(this.LoginName), "登录名不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(this.PasswordHash), "密码不能为空"); var isExistLoginName = _isNew ? _repository.IsExistLoginName(this.LoginName) : _repository.IsExistLoginName(this.LoginName, this.Id); ValidationObject.Validate(isExistLoginName, "登录名已存在"); }
public void Intercept(IInvocation invocation) { var permissionAttribute = invocation.Method.GetCustomAttribute <PermissionAttribute>(); if (permissionAttribute != null) { ValidationObject.Validate(!_currentUser.HasPermission(permissionAttribute.Code), "没有访问权限"); } invocation.Proceed(); }
public override bool Validate(ValidationObject businessObject) { try { return(GetPropertyValue(businessObject).ToString().Length > 0); } catch { return(false); } }
public async override Task Invoke(AspectContext context, AspectDelegate next) { var permissionAttribute = context.ServiceMethod.GetCustomAttribute <PermissionAttribute>(); if (permissionAttribute != null) { var currentUser = (ICurrentUser)context.ServiceProvider.GetService(typeof(ICurrentUser)); ValidationObject.Validate(!currentUser.HasPermission(permissionAttribute.Code), "没有访问权限"); } await next(context); }
public ICurrentUser Login(LoginInputDto input) { ValidationObject.Validate(string.IsNullOrWhiteSpace(input.LoginName), "登录名不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password), "密码不能为空"); var userDto = _userRepository.QueryableAsNoTracking.SingleOrDefault(t => t.LoginName == input.LoginName); ValidationObject.Validate(userDto == null, "登录名不存在"); ValidationObject.Validate(userDto.PasswordHash != input.Password, "密码不正确"); var currentUser = Get(userDto.Id); return(currentUser); }
/// <summary> /// Converts a value. /// </summary> /// <param name="value">The value produced by the binding source.</param> /// <param name="targetType">The type of the binding target property.</param> /// <param name="parameter">The converter parameter to use.</param> /// <param name="culture">The culture to use in the converter.</param> /// <returns> /// A converted value. If the method returns null, the valid null value is used. /// </returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //Parameter contains name of property to return validation on. //Value must be the ValidationObjectCollection. ValidationObject retVal = null; ValidationObjectCollection val = value as ValidationObjectCollection; if (val != null && parameter != null) { retVal = val.GetValidationResult(parameter.ToString()); } return(retVal); }
public void Add(AddInputDto input) { ValidationObject.Validate(string.IsNullOrWhiteSpace(input.LoginName), "登录名不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password), "密码不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password2), "确认密码不能为空"); ValidationObject.Validate(input.Password != input.Password2, "密码和确认密码不一致"); var exist = _userRepository.Queryable.Any(t => t.LoginName == input.LoginName); ValidationObject.Validate(exist, "登录名已存在"); var entity = _objectMapper.Map <AddInputDto, UserEntity>(input); _userRepository.Add(entity); }
public ICurrentUser Login(LoginInputDto input) { ValidationObject.Validate(string.IsNullOrWhiteSpace(input.LoginName), "登录名不能为空"); ValidationObject.Validate(string.IsNullOrWhiteSpace(input.Password), "密码不能为空"); var userDto = _repository.Get(input.LoginName); ValidationObject.Validate(userDto == null, "登录名不存在"); ValidationObject.Validate(userDto.PasswordHash != input.Password, "密码不正确"); var currentUser = _repository.Get(userDto.Id); return(currentUser); }
//Converts Fluent validation results into a common validation result object - so we can have consistent valdation results regardless of if they come from fluent validation or not public IList <ValidationObject> ConvertFluentValidationResults(IList <ValidationFailure> fluentValidationResults) { IList <ValidationObject> validationResults = new List <ValidationObject>(); //Loop the fluent validation results building up a list of validation objects foreach (ValidationFailure result in fluentValidationResults) { ValidationObject validationObject = new ValidationObject(result); validationResults.Add(validationObject); } return(validationResults); }
private bool ValidateExcelObject() { var validation = new ValidationObject(); validation.StartValidation(ref excelList, excelTemplate); if (validation.isError) { var messageLabel = WarningMessageBox.FindControl("WarningLabel") as System.Web.UI.WebControls.Label; messageLabel.Text = validation.GetMassegaForError(); WarningMessageBox.Show(); return(false); } return(true); }
public static DataValidationIssue validates(ValidationObject fieldView) { if (fieldView.isRequired) { if (string.IsNullOrWhiteSpace(fieldView.value)) { return new DataValidationIssue() { message = "Value is required", validationObject = fieldView } } ; } if (Constants.VALIDATION_PHONE.CompareTo(fieldView.validation) == 0) { //we look at the value specified var value = fieldView.value; if (string.IsNullOrWhiteSpace(value)) { return(null); } value = value.Trim(); var allDigits = removeNonDigits(value); var is10Chars = allDigits.Length == Constants.VALIDATION_PhoneNumberLength; var looksLikeCell = allDigits.StartsWith(Constants.VALIDATION_HowCellStarts); var looksLikePhone = allDigits.StartsWith(Constants.VALIDATION_HowPhoneStarts); if (allDigits.Length != value.Length || !(is10Chars && (looksLikeCell || looksLikePhone))) { return (new DataValidationIssue() { message = "Phone not in correct format", validationObject = fieldView }); } } return(null); } }
public static DataValidationIssue validates(ValidationObject fieldView) { if (fieldView.isRequired) { if (isNullDate(fieldView.value)) { return new DataValidationIssue() { message = "Value is required", validationObject = fieldView } } ; } return(null); }
protected virtual IEnumerable ValidateUrl(string url) { List <ValidationObject> result = null; if (string.IsNullOrEmpty(url) || string.IsNullOrWhiteSpace(url)) { result = new List <ValidationObject>(); ValidationObject obj = new ValidationObject("Url is required field.", ValidationObjectSeverity.Fatal); result.Add(obj); } else { Uri uriResult; bool isValid = Uri.TryCreate(url, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!isValid) { if (result == null) { result = new List <ValidationObject>(); } ValidationObject obj = new ValidationObject("Url is invalid.", ValidationObjectSeverity.Major); result.Add(obj); } if (url.ToLower().Contains("adult")) { if (result == null) { result = new List <ValidationObject>(); } ValidationObject obj = new ValidationObject("No adult content is allowed.", ValidationObjectSeverity.Minor); result.Add(obj); } } if (result != null && result.Count > 1) { result = result.OrderByDescending(i => (int)i.Severity).ToList(); } return(result); }
/// <summary> /// Method to delete an ingredient /// </summary> /// <param name="ingredient">The ingredient to delete</param> public async Task DeleteIngredientAsync(ComboBox ingredient) { var isValid = ValidationObject.ValidateIngredientSelection(ingredient); if (isValid) { var ingredientToDelete = ingredient.SelectedItem as IngredientDTO; var deleted = await BusinessObject.DeleteIngredientAsync(ingredientToDelete); if (deleted) { ShowMessage($"Recipe {ingredientToDelete.Name} Deleted Successfully"); } else { ShowMessage($"Recipe {ingredientToDelete.Name} Not Deleted"); } } }
/// <summary> /// Method to delete a cooking instruction from the database /// </summary> /// <param name="instruction"></param> /// <returns></returns> public async Task DeleteCookingInstructionAsync(ComboBox instruction) { var isValid = ValidationObject.ValidateInstructionSelection(instruction); if (isValid) { var instructionToDelete = instruction.SelectedItem as CookingInstructionDTO; var deleted = await BusinessObject.DeleteCookingInstructionAsync(instructionToDelete); if (deleted) { ShowMessage($"Cooking Instruction {instructionToDelete.Name} Deleted Successfully"); } else { ShowMessage($"Cooking Instruction {instructionToDelete.Name} Not Deleted"); } } }
/// <summary> /// Method to delete a recipe /// </summary> /// <param name="recipe">The recipe to delete</param> public async Task DeleteRecipeAsync(ComboBox recipe) { var isValid = ValidationObject.ValidateRecipeSelection(recipe); if (isValid) { var recipeToDelete = recipe.SelectedItem as RecipeDTO; var deleted = await BusinessObject.DeleteRecipeAsync(recipeToDelete); if (deleted) { ShowMessage($"Recipe {recipeToDelete.Name} Deleted Successfully"); } else { ShowMessage($"Recipe {recipeToDelete.Name} Not Deleted"); } } }
/// <summary> /// Method to add a cooking instruction to a recipe /// </summary> /// <param name="recipe">The recipe to add the cooking instruction to </param> /// <param name="instruction">The instruction to add to the recipe</param> public async Task AddCookingInstructionToRecipe(ComboBox recipe, ComboBox instruction) { var isRecipeValid = recipeUI.ValidationObject.ValidateRecipeSelection(recipe); var isInstructionValid = ValidationObject.ValidateInstructionSelection(instruction); if (isRecipeValid && isInstructionValid) { var recipeToAddInstruction = recipe.SelectedItem as RecipeDTO; var instructionToAddToRecipe = instruction.SelectedItem as CookingInstructionDTO; var added = await BusinessObject.AddCookingInstructionToRecipeAsync(recipeToAddInstruction, instructionToAddToRecipe); if (added) { ShowMessage($"Cooking Instruction {instructionToAddToRecipe.Name} Added To Recipe {recipeToAddInstruction.Name} "); } else { ShowMessage($"Cooking Instruction {instructionToAddToRecipe.Name} Not Added To Recipe {recipeToAddInstruction.Name} "); } } }
public void Validate() { var obj = new ValidationObject { GreaterThen5 = 10, Nested = new NestedValidationObject { GreaterThen5 = 10, NotEmpty = "This is not empty", NotNull = new object(), }, NotEmpty = "This is not empty", NotNull = new object(), List = new List <NestedValidationObject> { new NestedValidationObject { GreaterThen5 = 10, NotEmpty = "This is not empty", NotNull = new object(), }, new NestedValidationObject { GreaterThen5 = 10, NotEmpty = "This is not empty", NotNull = new object(), }, }, Version = "100.0" }; obj.Validate(out var errors) .Should() .BeTrue("the object is valid"); errors .Should() .BeEmpty("the object is valid"); }
/// <summary> /// Method to add an ingredient to a recipe /// </summary> /// <param name="recipe">The recipe to add the ingredient to</param> /// <param name="ingredient">The ingredient to add the recipe to</param> public async Task AddIngredientToRecipeAsync(ComboBox recipe, ComboBox ingredient) { var isRecipeValid = recipeUI.ValidationObject.ValidateRecipeSelection(recipe); var isIngredientValid = ValidationObject.ValidateIngredientSelection(ingredient); //Check if the recipe and ingredient is valid if (isRecipeValid && isIngredientValid) { var recipeToAddIngredientTo = recipe.SelectedItem as RecipeDTO; var ingredientToAddToRecipe = ingredient.SelectedItem as IngredientDTO; var added = await BusinessObject.AddIngredientToRecipeAsync(recipeToAddIngredientTo, ingredientToAddToRecipe); if (added) { ShowMessage($"Ingredient {ingredientToAddToRecipe.Name} Added To Recipe {recipeToAddIngredientTo.Name}"); } else { ShowMessage($"Ingredient {ingredientToAddToRecipe.Name} Not Added To Recipe {recipeToAddIngredientTo.Name}"); } } }
//static readonly ILog _log = LogManager.GetLogger(typeof(ValidationToBrush)); //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //parameter = "propertyMatch|Color If success|Color if Warning|Color if Error Brush retVal = null; ValidationObjectCollection validation = null; if (value != null) { validation = value as ValidationObjectCollection; if (parameter != null) { string[] parms = parameter.ToString().Split('|'); string key = parms[0]; ValidationObject val = validation.GetValidationResult(key); string colorOnSuccess = parms[1]; string colorOnWarn = parms[2]; string colorOnError = parms[3]; BrushConverter cnv = new BrushConverter(); switch (val.Code) { case ValidationValue.IsValid: retVal = cnv.ConvertFromInvariantString(colorOnSuccess) as Brush; break; case ValidationValue.IsWarnState: retVal = cnv.ConvertFromInvariantString(colorOnWarn) as Brush; break; case ValidationValue.IsError: retVal = cnv.ConvertFromInvariantString(colorOnError) as Brush; break; } } } return(retVal); }
/// <summary> /// Method to add an ingredient to the database /// </summary> /// <param name="ingredient">The name of the ingredient</param> /// <returns></returns> public async Task AddIngredient(TextBox ingredient) { var isValid = ValidationObject.ValidateIngredientName(ingredient); if (isValid) { var ingredientToAdd = new IngredientDTO() { Name = ingredient.Text }; var added = await BusinessObject.AddIngredientAsync(ingredientToAdd); if (added) { ShowMessage($"Ingredient {ingredientToAdd.Name} Added"); } else { ShowMessage($"Ingredient {ingredientToAdd.Name} Not Added"); } } }
/// <summary> /// Method to add a recipe to the database if valid /// </summary> /// <param name="name">The name of the recipe</param> public async Task AddRecipeAsync(TextBox name) { var isValid = ValidationObject.ValidateRecipeName(name); if (isValid) { var recipeToAdd = new RecipeDTO() { Name = name.Text }; var added = await BusinessObject.AddRecipeAsync(recipeToAdd); if (added) { ShowMessage($"Recipe {recipeToAdd.Name} Added"); name.Clear(); } else { ShowMessage($"Recipe {recipeToAdd.Name} Not Added"); } } }
protected virtual IEnumerable ValidateTitle(string title) { List <ValidationObject> result = null; if (string.IsNullOrEmpty(title) || string.IsNullOrWhiteSpace(title)) { result = new List <ValidationObject>(); ValidationObject obj = new ValidationObject("Title is required field.", ValidationObjectSeverity.Fatal); result.Add(obj); } else if (title.Length > 30) { result = new List <ValidationObject>(); ValidationObject obj = new ValidationObject("Title should not exceed 30 characters.", ValidationObjectSeverity.Minor); result.Add(obj); } if (result != null && result.Count > 1) { result = result.OrderBy(i => (int)i.Severity).ToList(); } return(result); }
/// <summary> /// Gets value for given validation object's property using reflection /// </summary> /// <param name="validationObject"></param> /// <returns></returns> protected object GetPropertyValue(ValidationObject validationObject) { // note: reflection is relatively slow return(validationObject.GetType().GetProperty(Property).GetValue(validationObject, null)); }
private ValidationObject ValidateOrder() { ValidationObject v = new ValidationObject { Passed = true, Errors = "" }; if (string.IsNullOrEmpty(Order.Product)) { v.Passed = false; v.Errors += "Product can not be blank\r\n"; } if (string.IsNullOrEmpty(Order.Instrument)) { v.Passed = false; v.Errors += "Instrument can not be blank\r\n"; } if (string.IsNullOrEmpty(Order.BuySell)) { v.Passed = false; v.Errors += "Buy/Sell can not be blank\r\n"; } if (Order.Quantity <= 0) { v.Passed = false; v.Errors += "Quantity must be greater than 0\r\n"; } return v; }
public override bool Validate(ValidationObject validationObject) { return(Regex.Match(GetPropertyValue(validationObject).ToString(), Pattern).Success); }