private async Task <bool> ValidateCode(RepairTicket RepairTicket) { if (string.IsNullOrWhiteSpace(RepairTicket.Code)) { RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeEmpty); } else { var Code = RepairTicket.Code; if (RepairTicket.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(RepairTicket.Code)) { RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeHasSpecialCharacter); } else { if (RepairTicket.Code.Length > 255) { RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeOverLength); } else { RepairTicketFilter RepairTicketFilter = new RepairTicketFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = RepairTicket.Id }, Code = new StringFilter { Equal = RepairTicket.Code }, Selects = RepairTicketSelect.Code }; int count = await UOW.RepairTicketRepository.Count(RepairTicketFilter); if (count != 0) { RepairTicket.AddError(nameof(RepairTicketValidator), nameof(RepairTicket.Code), ErrorCode.CodeExisted); } } } } return(RepairTicket.IsValidated); }
public async Task <bool> ValidateUsername(AppUser AppUser) { if (string.IsNullOrWhiteSpace(AppUser.Username)) { AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameEmpty); } else { var Code = AppUser.Username; if (AppUser.Username.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(AppUser.Username)) { AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameHasSpecialCharacter); } else if (AppUser.Username.Length > 255) { AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameOverLength); } AppUserFilter AppUserFilter = new AppUserFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = AppUser.Id }, Username = new StringFilter { Equal = AppUser.Username }, Selects = AppUserSelect.Username }; int count = await UOW.AppUserRepository.Count(AppUserFilter); if (count != 0) { AppUser.AddError(nameof(AppUserValidator), nameof(AppUser.Username), ErrorCode.UsernameExisted); } } return(AppUser.IsValidated); }
private async Task <bool> ValidateCode(WorkflowDefinition WorkflowDefinition) { if (string.IsNullOrWhiteSpace(WorkflowDefinition.Code)) { WorkflowDefinition.AddError(nameof(WorkflowDefinitionValidator), nameof(WorkflowDefinition.Code), ErrorCode.CodeEmpty); } else { var Code = WorkflowDefinition.Code; if (WorkflowDefinition.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(WorkflowDefinition.Code)) { WorkflowDefinition.AddError(nameof(WorkflowDefinitionValidator), nameof(WorkflowDefinition.Code), ErrorCode.CodeHasSpecialCharacter); } WorkflowDefinitionFilter WorkflowDefinitionFilter = new WorkflowDefinitionFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = WorkflowDefinition.Id }, Code = new StringFilter { Equal = WorkflowDefinition.Code }, Selects = WorkflowDefinitionSelect.Code }; int count = await UOW.WorkflowDefinitionRepository.Count(WorkflowDefinitionFilter); if (count != 0) { WorkflowDefinition.AddError(nameof(WorkflowDefinitionValidator), nameof(WorkflowDefinition.Code), ErrorCode.CodeExisted); } } return(WorkflowDefinition.IsValidated); }
public async Task <bool> ValidateCode(CallType CallType) { if (string.IsNullOrWhiteSpace(CallType.Code)) { CallType.AddError(nameof(CallTypeValidator), nameof(CallType.Code), ErrorCode.CodeEmpty); } else { var Code = CallType.Code; if (CallType.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(CallType.Code)) { CallType.AddError(nameof(CallTypeValidator), nameof(CallType.Code), ErrorCode.CodeHasSpecialCharacter); } CallTypeFilter CallTypeFilter = new CallTypeFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = CallType.Id }, Code = new StringFilter { Equal = CallType.Code }, Selects = CallTypeSelect.Code }; int count = await UOW.CallTypeRepository.Count(CallTypeFilter); if (count != 0) { CallType.AddError(nameof(CallTypeValidator), nameof(CallType.Code), ErrorCode.CodeExisted); } } return(CallType.IsValidated); }
public async Task <bool> ValidateCode(KnowledgeGroup KnowledgeGroup) { if (string.IsNullOrWhiteSpace(KnowledgeGroup.Code)) { KnowledgeGroup.AddError(nameof(KnowledgeGroupValidator), nameof(KnowledgeGroup.Code), ErrorCode.CodeEmpty); } else { var Code = KnowledgeGroup.Code; if (KnowledgeGroup.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(KnowledgeGroup.Code)) { KnowledgeGroup.AddError(nameof(KnowledgeGroupValidator), nameof(KnowledgeGroup.Code), ErrorCode.CodeHasSpecialCharacter); } KnowledgeGroupFilter KnowledgeGroupFilter = new KnowledgeGroupFilter { Skip = 0, Take = 10, Id = new IdFilter { NotEqual = KnowledgeGroup.Id }, Code = new StringFilter { Equal = KnowledgeGroup.Code }, Selects = KnowledgeGroupSelect.Code }; int count = await UOW.KnowledgeGroupRepository.Count(KnowledgeGroupFilter); if (count != 0) { KnowledgeGroup.AddError(nameof(KnowledgeGroupValidator), nameof(KnowledgeGroup.Code), ErrorCode.CodeExisted); } } return(KnowledgeGroup.IsValidated); }