//Kiểm tra dữ liệu public bool ValidateContact(NguoiDung Username) { _validationDictionary.Clear(); if (Username.ID.Trim().Length == 0) { _validationDictionary.AddError("Username", "Không được bỏ trống tên tài khoản"); } if (Username.Pass != null) { if (Username.Pass.Trim().Length == 0) { _validationDictionary.AddError("Password", "Không được bỏ trống mật khẩu"); } } if (Username.ID.Length > 0 && !Regex.IsMatch(Username.ID, @"\w")) { _validationDictionary.AddError("Username", "Ký tự đặc biệt"); } if (Username.Mail != null) { if (Username.Mail.Length == 0) { _validationDictionary.AddError("Email", "Vui lòng nhập Email"); } if (Username.Mail.Length > 0 && !Regex.IsMatch(Username.Mail, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")) { _validationDictionary.AddError("Email", "Vui lòng nhập mail hợp lệ"); } } return(_validationDictionary.IsValid); }
public bool ValidateTask(Task taskToValidate) { //convert null values to default strings taskToValidate.Subject = taskToValidate.Subject ?? ""; if (taskToValidate.Subject.Trim().Length == 0) { _validationDictionary.AddError("Task.Subject", "A Subject is required."); } if (taskToValidate.StartDate < DateTime.Now) { _validationDictionary.AddError("Task.StartDate", "The Start Date must be greater or equals to current date time."); return(_validationDictionary.IsValid); } if (taskToValidate.EndDate <= taskToValidate.StartDate) { _validationDictionary.AddError("Task.EndDate", "The End Date must be greater than Start date."); return(_validationDictionary.IsValid); } if (taskToValidate.LimitDate < taskToValidate.StartDate || taskToValidate.LimitDate > taskToValidate.EndDate) { _validationDictionary.AddError("Task.LimitDate", "The Limit Date must be within Start Date and End Date interval."); } return(_validationDictionary.IsValid); }
public List <string> ValidateLoginRequirement(LoginViewModel model) { //Check if the user password is expired if (DateTime.UtcNow.Date >= _accountRepository.GetPasswordExpiryDate(model.Username)) { _validationDictionary.AddError(_config.GetSection("Messages")["ExpiredPassword"]); } //Check if End of day is in progress if (_accountRepository.GetUserStatus(model.Username).Contains("EOD")) { _validationDictionary.AddError(_config.GetSection("Messages")["EODInProgress"]); } //Check if the user is Active or not if (_accountRepository.GetUserStatus(model.Username) == "DISABLED" || _accountRepository.GetUserStatus(model.Username) == "PENDING") { _validationDictionary.AddError(_config.GetSection("Messages")["UserDisabled"]); } //This checks if the user is logged in already if (_accountRepository.UserIsLoggedIn(model.Username)) { _validationDictionary.AddError(string.Format(_config.GetSection("Messages")["UserLoggedIn"], model.Username)); } return(_validationDictionary.GetValidationErrors()); }
public bool ValidateContact(Contact contactToValidate) { //convert null values to empty strings contactToValidate.FirstName = contactToValidate.FirstName ?? ""; contactToValidate.LastName = contactToValidate.LastName ?? ""; contactToValidate.Address = contactToValidate.Address ?? ""; contactToValidate.Email = contactToValidate.Email ?? ""; if (contactToValidate.FirstName.Trim().Length == 0) { _validationDictionary.AddError("Contact.FirstName", "First name is required."); } if (contactToValidate.LastName.Trim().Length == 0) { _validationDictionary.AddError("Contact.LastName", "Last name is required."); } if (contactToValidate.Address.Trim().Length == 0) { _validationDictionary.AddError("Contact.Address", "Address is required."); } if (contactToValidate.Email.Length > 0 && !Regex.IsMatch(contactToValidate.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")) { _validationDictionary.AddError("Contact.Email", "Invalid email address."); } return(_validationDictionary.IsValid); }
public bool ValidateString(String key) { _validationDictionary.Clear(); if (key.Trim().Length > 0 && !Regex.IsMatch(key, @"\w")) { _validationDictionary.AddError("Timkiem", "Vui lòng nhập từ khóa hợp lệ"); } return(_validationDictionary.IsValid); }
public static void ValidDateOfBirth(IValidationDictionary aValidationDictionary, DateTime aDateOfBirth) { if (aDateOfBirth.Year == 1) { aValidationDictionary.AddError("DateOfBirth", aDateOfBirth.ToString(), "Date of Birth required."); } if (aDateOfBirth > DateTime.Today.AddYears(-18)) { aValidationDictionary.AddError("DateOfBirth", aDateOfBirth.ToString(), "You must be at least 18 years old."); } }
//Handle individual profile processes #region public async Task <bool> ValidateIndividualProfile(IndividualProfileViewModel model) { response = await client.GetAsync("api.bankmodel/customerservice/individual-profile-exist/" + model); if (Convert.ToBoolean(response.Content.ReadAsStringAsync().Result) == true) { _validationDictionary.AddError("", string.Format(_config.GetSection("Messages")["ObjectExist"], string.Concat(model.Title, " ", model.Lastname, ", ", model.Othernames))); } response = await client.GetAsync("api.bankmodel/customerservice/phone-number-exist/" + model.PhoneNumber); if (Convert.ToBoolean(response.Content.ReadAsStringAsync().Result) == true) { _validationDictionary.AddError("", string.Format(_config.GetSection("Messages")["ObjectExist"], string.Concat("Phone number ", model.PhoneNumber))); } response = await client.GetAsync("api.bankmodel/customerservice/email-exist/" + model.Email); if (Convert.ToBoolean(response.Content.ReadAsStringAsync().Result) == true) { _validationDictionary.AddError("", string.Format(_config.GetSection("Messages")["ObjectExist"], string.Concat("Email address ", model.Email))); } return(_validationDictionary.IsValid); }
protected void RaiseError(string error, string field) { if (ValidationDictionary != null) { ValidationDictionary.AddError(field, error); } else { throw new Exception(error); } }
public void Validate(Team team) { if (team.Name == null || team.Name.Trim().Length == 0) { _validationDictionary.AddError("Name", "Name is required."); } if (team.Name != null && team.Name.Trim().Length < 2) { _validationDictionary.AddError("Content", "Name must contain at least 2 characters."); } }
protected bool ValidateVehicleModel(VehicleModel vehicleModel) { if (vehicleModel.Name == null) { _validationDictionary.AddError("Name", "Name is required."); } if (vehicleModel.Abrv == null) { _validationDictionary.AddError("Abrv", "Abrv is required."); } return(_validationDictionary.IsValid); }
protected async Task <bool> ValidateSystemUser(SystemUsersViewModel model) { //Check if the proposed Username exist already var userResult = await _userManager.FindByNameAsync(model.Username.ToLower()); if (userResult != null) { _validationDictionary.AddError("", string.Format(_config.GetSection("Messages")["ObjectExist"], model.Username)); } return(_validationDictionary.IsValid); }
public void CheckTitleNote(string propatyName, string note, string title, IValidationDictionary validationDic) { if (validationDic == null) { throw new ArgumentNullException(nameof(validationDic)); } if (!string.IsNullOrEmpty(note) && !string.IsNullOrEmpty(title) && note.IndexOf(title, StringComparison.Ordinal) < 0) { validationDic.AddError(propatyName, "本文中にタイトルが記述されていません。"); validationDic.AddError(propatyName, "もひとつエラー。"); } }
public static bool ValidPassword(IValidationDictionary aValidationDictionary, string aPassword, string aRetypedPassword) { if (aPassword.Trim().Length == 0) { aValidationDictionary.AddError("Password", "", "Password is required."); } if (aRetypedPassword == null || aRetypedPassword.Trim().Length == 0) { aValidationDictionary.AddError("RetypedPassword", "", "Please type your password again."); } else if (!aPassword.Equals(aRetypedPassword)) { aValidationDictionary.AddError("RetypedPassword", "", "Passwords must match."); } return aValidationDictionary.isValid; }
private bool ValidateCode(MaKhuyenMai codetoValidate) { _validationDictionary.Clear(); if (codetoValidate.MaKM.Length == 0) { _validationDictionary.AddError("MaKM", "Vui lòng nhập mã khuyến mãi"); } if (codetoValidate.TiLe < 0 || codetoValidate.TiLe > 100) { _validationDictionary.AddError("TiLe", "Vui lòng nhập tỉ lệ hợp lệ"); } return(_validationDictionary.IsValid); }
protected bool ValidateVehicleModel(VehicleModel vehicleModelToValidate) { if (vehicleModelToValidate.Name == null) { _validationDictionary.AddError("Name", "Name is required."); } if (vehicleModelToValidate.Abbreviation == null) { _validationDictionary.AddError("Abbreviation", "Abbreviation is required."); } return(_validationDictionary.IsValid); }
private void Validate(ScrumTask task) { if (task.Title == null || task.Title.Trim().Length == 0) { _validationDictionary.AddError("Content", "Title is required."); } if (task.Title != null && task.Title.Trim().Length < 3) { _validationDictionary.AddError("Content", "Title must contain at least 3 characters."); } if (task.Title != null && task.Title.Trim().Length > 40) { _validationDictionary.AddError("Content", "Title must contain less than 40 characters."); } if (task.Content == null || task.Content.Trim().Length == 0) { _validationDictionary.AddError("Content", "Content is required."); } if (task.Content != null && task.Content.Trim().Length < 3) { _validationDictionary.AddError("Content", "Content must contain at least 3 characters."); } if (task.Content != null && task.Content.Trim().Length > 2000) { _validationDictionary.AddError("Content", "Content must contain less than 2000 characters."); } if (_unitOfWork.Sprints.Get(task.SprintId) == null) { _validationDictionary.AddError("SprintId", "Sprint with this id does not exist."); } }
public bool ValidateOpportunity(Opportunity opportunityToValidate) { //convert null values to empty strings opportunityToValidate.Description = opportunityToValidate.Description ?? ""; if (opportunityToValidate.Amount <= 0) { _validationDictionary.AddError("Opportunity.Amount", "Amount must be greater than 0."); } if (opportunityToValidate.Description.Trim().Length == 0) { _validationDictionary.AddError("Opportunity.Description", "Description is required."); } return(_validationDictionary.IsValid); }
// Contact methods public bool ValidateContact(ContactMaster contactToValidate) { if (contactToValidate.FirstName == null || contactToValidate.FirstName.Trim().Length == 0) { _validationDictionary.AddError("FirstName", "First name is required."); } else if (contactToValidate.FirstName == null || contactToValidate.FirstName.Trim().Length > 50) { _validationDictionary.AddError("FirstName", "First name cannot be longer than 50 characters."); } if (contactToValidate.LastName == null || contactToValidate.LastName.Trim().Length == 0) { _validationDictionary.AddError("LastName", "Last name is required."); } else if (contactToValidate.LastName == null || contactToValidate.LastName.Trim().Length > 50) { _validationDictionary.AddError("LastName", "Last name cannot be longer than 50 characters."); } if (contactToValidate.Phone == null || contactToValidate.Phone.Trim().Length == 0) { _validationDictionary.AddError("Phone", "Phone is required."); } else if (contactToValidate.Phone == null || contactToValidate.Phone.Length > 0 && !Regex.IsMatch(contactToValidate.Phone, @"^(\+\d{1,3}[- ]?)?\d{10}$")) { _validationDictionary.AddError("Phone", "Invalid phone number."); } else if (contactToValidate.Phone == null || contactToValidate.Phone.Trim().Length > 20) { _validationDictionary.AddError("Phone", "Phone cannot be longer than 20 characters."); } if (contactToValidate.Email == null || contactToValidate.Email.Trim().Length == 0) { _validationDictionary.AddError("Email", "Email is required."); } else if (contactToValidate.Email == null || contactToValidate.Email.Length > 0 && !Regex.IsMatch(contactToValidate.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")) { _validationDictionary.AddError("Email", "Invalid email address."); } else if (contactToValidate.Email == null || contactToValidate.Email.Trim().Length > 150) { _validationDictionary.AddError("Email", "Email cannot be longer than 150 characters."); } return(_validationDictionary.IsValid); }
/// <summary> /// 把錯誤訊息記錄到IValidationDictionary的物件裡面 /// </summary> /// <param name="validationDictionary">儲存目前Validation結果的Dictionary</param> /// <param name="propertyErrors">要記錄到ValidationDictionary裡面的錯誤訊息</param> public static void AddValidationErrors(this IValidationDictionary validationDictionary, IValidationErrors propertyErrors) { foreach (var databaseValidationError in propertyErrors.Errors) { validationDictionary.AddError(databaseValidationError.PropertyName, databaseValidationError.PropertyExceptionMessage); } }
protected bool ValidateProduct(Product productToValidate) { if (productToValidate.Name.Trim().Length == 0) { _validatonDictionary.AddError("Name", "Name is required."); } if (productToValidate.Description.Trim().Length == 0) { _validatonDictionary.AddError("Description", "Description is required."); } if (productToValidate.UnitsInStock < 0) { _validatonDictionary.AddError("UnitsInStock", "Units in stock cannot be less than zero."); } return(_validatonDictionary.IsValid); }
public bool ValidateKhachHang(KhachHang khToValidate) { _validationDictionary.Clear(); if (khToValidate.tenkh.Trim().Length == 0) { _validationDictionary.AddError("TenKH", "Chưa nhập tên khách hàng."); } if (khToValidate.dienthoai.Trim().Length < 10 || khToValidate.dienthoai.Trim().Length > 11 || IsPhoneNumber(khToValidate.dienthoai.Trim())) { _validationDictionary.AddError("DienThoai", "Chưa nhập số điện hoặc chứa ký tự."); } if (khToValidate.diachi.Trim().Length == 0) { _validationDictionary.AddError("DiaChi", "Chưa nhập địa chỉ."); } return(_validationDictionary.IsValid); }
public bool ValidateNhanVien(NhanVien nvToValidate) { _validationDictionary.Clear(); if (nvToValidate.tennv.Trim().Length == 0) { _validationDictionary.AddError("TenNV", "Chưa nhập tên nhân viên."); } if (nvToValidate.dienthoai.Trim().Length < 10 || nvToValidate.dienthoai.Trim().Length > 11 || IsPhoneNumber(nvToValidate.dienthoai.Trim())) { _validationDictionary.AddError("DienThoai", "Chưa nhập số điện hoặc chứa ký tự."); } if (nvToValidate.diachi.Trim().Length == 0) { _validationDictionary.AddError("DiaChi", "Chưa nhập địa chỉ."); } return(_validationDictionary.IsValid); }
// Add new Teacher public async Task <bool> AddTeacher(TeacherCreateViewModel model) { var existingUser = await _userManager.FindByEmailAsync(model.Email); if (existingUser != null) { _validatonDictionary.AddError("Email", "Пользователь с таким e-mail уже существует."); } bool teacherExist = await IsThisTeacherExists(model); if (teacherExist) { _validatonDictionary.AddError("", "Учитель с таким ФИО уже существует."); } if (_validatonDictionary.IsValid) { var user = new ApplicationUser { Email = model.Email, UserName = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (!result.Succeeded) { foreach (string errorMessage in result.Errors) { _validatonDictionary.AddError("", errorMessage); } return(false); } var teacher = Mapper.Map <Teacher>(model); teacher.UserId = user.Id; _teacherRepository.CreateTeacher(teacher); return(true); } else { return(false); } }
public override bool Validate(IValidationDictionary validationDictionary) { if (Value.IsEmpty()) { validationDictionary.AddError("Properties", "A file upload is required"); return(false); } return(true); }
protected bool ValidateNews(News news) { if (news.Title.Trim().Length == 0) { _validatonDictionary.AddError("Title", "Title is required."); } return(_validatonDictionary.IsValid); }
public static bool RaiseError(IValidationDictionary validationDictionary, string fieldName, string errorMessage) { if (validationDictionary != null) { validationDictionary.AddError(fieldName, errorMessage); return(false); } throw new Exception(errorMessage); }
public override bool Validate(IValidationDictionary validationDictionary) { if (OptionID == 0) { validationDictionary.AddError("Properties", "You must select an option"); return(false); } return(true); }
public bool Create(Todo todo) { if (!ValidateTodo(todo)) { return(false); } try { _repository.Create(todo); } catch (Exception ex) { _validationDictionary.AddError(ex.Source, ex.Message); } return(true); }
protected bool ValidateProduct(ProductModel pm) { if (string.IsNullOrEmpty(pm.Name)) { _validatonDictionary.AddError("Name", "Name is required."); } return(_validatonDictionary.IsValid); }
public bool ValidationAccount(Account acc) { _validation.DictionaryClear(); if (acc.userName.Length <= 0) { _validation.AddError("username", "Tên đăng nhập rỗng"); } return(_validation.IsValid); }
public async Task <bool> InsertOrderAsync(OrderServiceModel order) { try { await _unitOfWork.BeginTransactionAsync(); var products = await _unitOfWork.ProductRepository.GetAllAsyncWithTracking(); var users = await _unitOfWork.UserRepository.GetAllAsyncWithNoTracking(); var user = users.FirstOrDefault(x => x.Id == order.UserId); if (user == null) { _validationDictionary.AddError("UserId", "შეყვანილი იუზერი არ არსებობს!"); return(false); } var newOrder = new OrderDTO { UserId = order.UserId, }; await _unitOfWork.OrderRepository.InsertAsync(newOrder); if (!await AddOrderProduct(order, products.ToList(), newOrder.Id)) { await _unitOfWork.RollbackAsync(); return(false); } await _unitOfWork.SaveChangesAsync(); await _unitOfWork.CommitAsync(); return(true); } catch (Exception) { await _unitOfWork.RollbackAsync(); throw; } }
public bool ValidateIndustrialSector(IndustrialSector sectorToValidate) { //convert null values to empty strings sectorToValidate.Sector = sectorToValidate.Sector ?? ""; if (sectorToValidate.Sector.Trim().Length == 0) { _validationDictionary.AddError("Sector", "Sector is required."); } return(_validationDictionary.IsValid); }
public static bool IsValidUniversityEmail(string anEmail, IValidationDictionary aValidationDictionary) { IUniversityService theUniversityService = new UniversityService(aValidationDictionary); if (!theUniversityService.IsValidUniversityEmailAddress(anEmail)) { IEnumerable<string> myValidEmails = theUniversityService.ValidEmails(); string myValidEmailsInString = string.Join(",", myValidEmails); aValidationDictionary.AddError("Email", anEmail, "I'm sorry that is not a valid University email. We currently only accept the following emails: " + myValidEmailsInString); } return aValidationDictionary.isValid; }
public bool Validate(object value,IValidationDictionary errorBag) { //if (errorBag == null) throw new ArgumentNullException("errorBag"); foreach(var validator in _validators) { if (!validator.IsValid(value)) { if (errorBag!=null) errorBag.AddError(ReflectionInfo.Name,validator.FormatErrorMessage(ReflectionInfo.Name)); return false; } } return true; }
/// <summary> /// validate post /// </summary> /// <param name="post">post</param> /// <param name="validation">validation dictionary</param> private void ValidatePost(Post post, IValidationDictionary validation) { if(!SlugIsUnique(post.PostId, post.Slug)) validation.AddError("Slug", "Slug is already in use."); }
public bool IsValid(IValidationDictionary validationDictionary) { // Required fields if (Title.IsNullEmptyOrWhitespace()) { validationDictionary.AddError("Title", "Required field."); } if (CommentText.IsNullEmptyOrWhitespace()) { validationDictionary.AddError("CommentText", "Required field."); } if (EmailOnReply && EmailAddress.IsNullEmptyOrWhitespace()) { validationDictionary.AddError("EmailAddress", "Email Address required for reply notification"); } // Regex patterns if (!EmailAddress.IsNullEmptyOrWhitespace() && !EmailAddress.IsEmailAddress()) { validationDictionary.AddError("EmailAddress", "Must be a valid email address."); } if (!Website.IsNullEmptyOrWhitespace() && !Website.IsHttpUrl()) { validationDictionary.AddError("Website", "Must be a valid URL (include http:// part, or leave blank)."); } // Max length violations if((Title ?? "").Trim().Length > TitleMaxLength) { validationDictionary.AddError("Title", "Cannot be longer than " + TitleMaxLength + " characters."); } if ((YourName ?? "").Trim().Length > NameMaxLength) { validationDictionary.AddError("YourName", "Cannot be longer than " + NameMaxLength + " characters."); } if ((EmailAddress ?? "").Trim().Length > EmailAddressMaxLength) { validationDictionary.AddError("EmailAddress", "Cannot be longer than " + EmailAddressMaxLength + " characters."); } if ((Website ?? "").Trim().Length > WebsiteMaxLength) { validationDictionary.AddError("Website", "Cannot be longer than " + WebsiteMaxLength + " characters."); } if ((CommentText ?? "").Trim().Length > CommentTextMaxLength) { validationDictionary.AddError("CommentText", "Cannot be longer than " + CommentTextMaxLength + " characters."); } // Recaptcha if (!PassesCaptchaValidation) { validationDictionary.AddError("Captcha", "Failed Captcha test, please try again."); } return validationDictionary.IsValid; }
/// <summary> /// validate page /// </summary> /// <param name="page">page</param> /// <param name="validation">validation dictionary</param> private void ValidatePage(Page page, IValidationDictionary validation) { if (!SlugIsUnique(page.PageId, page.Slug)) validation.AddError("Slug", "Slug is already in use."); }
/// <summary> /// copies errors to another dictionary /// </summary> /// <param name="other"></param> public void CopyTo(IValidationDictionary other) { if (other == null) throw new ArgumentNullException("other"); foreach(var kv in err) other.AddError(kv.Key,kv.Value); }
private void ValidateNewUser(RegisterModel model, IValidationDictionary validation) { var existingUser = _context.Users.SingleOrDefault(x => x.UserName == model.UserName); if (existingUser != null) validation.AddError("UserName", "This user name is already in use."); }