Пример #1
0
 public async Task <bool> ValidateName(SmsTemplate SmsTemplate)
 {
     if (string.IsNullOrWhiteSpace(SmsTemplate.Name))
     {
         SmsTemplate.AddError(nameof(SmsTemplateValidator), nameof(SmsTemplate.Name), ErrorCode.NameEmpty);
     }
     return(SmsTemplate.IsValidated);
 }
Пример #2
0
        public async Task <bool> ValidateCode(SmsTemplate SmsTemplate)
        {
            if (string.IsNullOrWhiteSpace(SmsTemplate.Code))
            {
                SmsTemplate.AddError(nameof(SmsTemplateValidator), nameof(SmsTemplate.Code), ErrorCode.CodeEmpty);
            }
            else
            {
                var Code = SmsTemplate.Code;
                if (SmsTemplate.Code.Contains(" ") || !FilterExtension.ChangeToEnglishChar(Code).Equals(SmsTemplate.Code))
                {
                    SmsTemplate.AddError(nameof(SmsTemplateValidator), nameof(SmsTemplate.Code), ErrorCode.CodeHasSpecialCharacter);
                }

                SmsTemplateFilter SmsTemplateFilter = new SmsTemplateFilter
                {
                    Skip = 0,
                    Take = 10,
                    Id   = new IdFilter {
                        NotEqual = SmsTemplate.Id
                    },
                    Code = new StringFilter {
                        Equal = SmsTemplate.Code
                    },
                    Selects = SmsTemplateSelect.Code
                };

                int count = await UOW.SmsTemplateRepository.Count(SmsTemplateFilter);

                if (count != 0)
                {
                    SmsTemplate.AddError(nameof(SmsTemplateValidator), nameof(SmsTemplate.Code), ErrorCode.CodeExisted);
                }
            }
            return(SmsTemplate.IsValidated);
        }
Пример #3
0
        public async Task <bool> ValidateId(SmsTemplate SmsTemplate)
        {
            SmsTemplateFilter SmsTemplateFilter = new SmsTemplateFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = SmsTemplate.Id
                },
                Selects = SmsTemplateSelect.Id
            };

            int count = await UOW.SmsTemplateRepository.Count(SmsTemplateFilter);

            if (count == 0)
            {
                SmsTemplate.AddError(nameof(SmsTemplateValidator), nameof(SmsTemplate.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }