public async Task <bool> ValidateName(Nation Nation) { if (string.IsNullOrWhiteSpace(Nation.Name)) { Nation.AddError(nameof(NationValidator), nameof(Nation.Name), ErrorCode.NameEmpty); } else if (Nation.Name.Length > 255) { Nation.AddError(nameof(NationValidator), nameof(Nation.Name), ErrorCode.NameOverLength); } return(Nation.IsValidated); }
public async Task <bool> ValidateCode(Nation Nation) { if (string.IsNullOrWhiteSpace(Nation.Code)) { Nation.AddError(nameof(NationValidator), nameof(Nation.Code), ErrorCode.CodeEmpty); } else { var Code = Nation.Code; if (Nation.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(Nation.Code)) { Nation.AddError(nameof(NationValidator), nameof(Nation.Code), ErrorCode.CodeHasSpecialCharacter); } NationFilter NationFilter = new NationFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = Nation.Id }, Code = new StringFilter { Equal = Nation.Code }, Selects = NationSelect.Code }; int count = await UOW.NationRepository.Count(NationFilter); if (count != 0) { Nation.AddError(nameof(NationValidator), nameof(Nation.Code), ErrorCode.CodeExisted); } } return(Nation.IsValidated); }
public async Task <bool> ValidateId(Nation Nation) { NationFilter NationFilter = new NationFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = Nation.Id }, Selects = NationSelect.Id }; int count = await UOW.NationRepository.Count(NationFilter); if (count == 0) { Nation.AddError(nameof(NationValidator), nameof(Nation.Id), ErrorCode.IdNotExisted); } return(count == 1); }