Exemple #1
0
        private async Task <bool> ValidateCode(District District)
        {
            if (string.IsNullOrEmpty(District.Code))
            {
                District.AddError(nameof(DistrictValidator), nameof(District.Code), ErrorCode.CodeEmpty);
                return(false);
            }
            DistrictFilter DistrictFilter = new DistrictFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    NotEqual = District.Id
                },
                Code = new StringFilter {
                    Equal = District.Code
                },
                Selects = DistrictSelect.Code
            };

            int count = await UOW.DistrictRepository.Count(DistrictFilter);

            if (count != 0)
            {
                District.AddError(nameof(DistrictValidator), nameof(District.Code), ErrorCode.CodeExisted);
            }
            return(count == 0);
        }
Exemple #2
0
 private async Task <bool> ValidateName(District District)
 {
     if (string.IsNullOrEmpty(District.Name))
     {
         District.AddError(nameof(DistrictValidator), nameof(District.Name), ErrorCode.NameEmpty);
         return(false);
     }
     if (District.Name.Length > 255)
     {
         District.AddError(nameof(DistrictValidator), nameof(District.Name), ErrorCode.NameOverLength);
         return(false);
     }
     return(true);
 }
Exemple #3
0
        public async Task <bool> ValidateId(District District)
        {
            DistrictFilter DistrictFilter = new DistrictFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = District.Id
                },
                Selects = DistrictSelect.Id
            };

            int count = await UOW.DistrictRepository.Count(DistrictFilter);

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