Beispiel #1
0
        public void Validate(IContractorRepository contractorRepository)
        {
            if (string.IsNullOrEmpty(CompanyName))
            {
                throw new EntityModelException(nameof(CompanyName), "The company name is mandatory.");
            }

            CasCode = CasCode?.Trim();
            CspCode = CspCode?.Trim();

            if (string.IsNullOrEmpty(CasCode) && string.IsNullOrEmpty(CspCode))
            {
                throw new EntityModelException($"{nameof(CasCode)}+{nameof(CspCode)}", "The CASCode and the CSPCode can not be both empty.");
            }

            if (!string.IsNullOrEmpty(CasCode) && !string.IsNullOrEmpty(CspCode))
            {
                throw new EntityModelException($"{nameof(CasCode)}+{nameof(CspCode)}", "The CASCode and the CSPCode can not have both values.");
            }

            if (!contractorRepository.IsUnique(this))
            {
                throw new EntityModelException($"{nameof(CompanyName)}", "There is another contractor with the same company name.");
            }
        }