Ejemplo n.º 1
0
        public async Task <bool> ValidatePhone(Company Company)
        {
            if (!string.IsNullOrWhiteSpace(Company.Phone))
            {
                if (Company.Phone.Length > 20)
                {
                    Company.AddError(nameof(CompanyValidator), nameof(Customer.Phone), ErrorCode.PhoneOverLength);
                }
                else
                {
                    CompanyFilter CompanyFilter = new CompanyFilter
                    {
                        Skip = 0,
                        Take = 10,
                        Id   = new IdFilter {
                            NotEqual = Company.Id
                        },
                        Phone = new StringFilter {
                            Equal = Company.Phone
                        }
                    };

                    int count = await UOW.CompanyRepository.Count(CompanyFilter);

                    if (count != 0)
                    {
                        Company.AddError(nameof(CompanyValidator), nameof(Company.Phone), ErrorCode.PhoneExisted);
                    }
                }
            }
            return(Company.IsValidated);
        }
Ejemplo n.º 2
0
 public async Task <bool> ValidateName(Company Company)
 {
     if (string.IsNullOrWhiteSpace(Company.Name))
     {
         Company.AddError(nameof(CompanyValidator), nameof(Company.Name), ErrorCode.NameEmpty);
     }
     else if (Company.Name.Length > 500)
     {
         Company.AddError(nameof(CompanyValidator), nameof(Company.Name), ErrorCode.NameOverLength);
     }
     return(Company.IsValidated);
 }
Ejemplo n.º 3
0
 public async Task <bool> ValidateAddress(Company Company)
 {
     if (!string.IsNullOrWhiteSpace(Company.Address) && Company.Address.Length > 1000)
     {
         Company.AddError(nameof(CompanyValidator), nameof(Company.Address), ErrorCode.AddressIsOverLenth);
     }
     return(Company.IsValidated);
 }
Ejemplo n.º 4
0
        public async Task <bool> ValidateAppUser(Company Company)
        {
            if (Company.AppUserId.HasValue)
            {
                AppUserFilter AppUserFilter = new AppUserFilter
                {
                    Id = new IdFilter {
                        Equal = Company.AppUserId
                    }
                };

                var count = await UOW.AppUserRepository.Count(AppUserFilter);

                if (count == 0)
                {
                    Company.AddError(nameof(CompanyValidator), nameof(Company.AppUserId), ErrorCode.AppUserNotExisted);
                }
            }
            else
            {
                Company.AddError(nameof(CompanyValidator), nameof(Company.AppUserId), ErrorCode.AppUserEmpty);
            }
            return(Company.IsValidated);
        }
Ejemplo n.º 5
0
        public async Task <bool> ValidateId(Company Company)
        {
            CompanyFilter CompanyFilter = new CompanyFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = Company.Id
                },
                Selects = CompanySelect.Id
            };

            int count = await UOW.CompanyRepository.Count(CompanyFilter);

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