Beispiel #1
0
 public HomeController(IEmployeeRespository employeeRespository, IWebHostEnvironment webHostEnvironment,
                       ILogger <HomeController> logger)
 {
     _employeeRespository = employeeRespository;
     _webHostEnvironment  = webHostEnvironment;
     this.logger          = logger;
 }
 public EmployeeValidator(IEmployeeRespository employeeRespository)
 {
     RuleSet(ValidatorTypeConstants.Create, () =>
     {
         BaseValidator();
         RuleFor(e => e.UserId).Must((e, val) => !employeeRespository.Any(ea => ea.UserId == val))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         RuleFor(e => e.Name).Must((e, val) => !employeeRespository.Any(ea => ea.Name == val))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         RuleFor(e => e.Mobile).Must((e, val) => !employeeRespository.Any(ea => ea.Mobile == val))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         RuleFor(e => e.Email).Must((e, val) => !employeeRespository.Any(ea => ea.Email == val))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
     });
     RuleSet(ValidatorTypeConstants.Modify, () =>
     {
         RuleFor(e => e.UserId).Must((e, val) => !employeeRespository.Any(ea => ea.UserId == val && ea.Id != e.Id))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         RuleFor(e => e.Name).Must((e, val) => !employeeRespository.Any(ea => ea.Name == val && ea.Id != e.Id))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         RuleFor(e => e.Mobile).Must((e, val) => !employeeRespository.Any(ea => ea.Mobile == val && ea.Id != e.Id))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         RuleFor(e => e.Email).Must((e, val) => !employeeRespository.Any(ea => ea.Email == val && ea.Id != e.Id))
         .WithMessage((e, val) => string.Format(ErrorMessage.IsNameRepeat, val));
         BaseValidator();
     });
 }
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IEmployeeRespository employeeRespository, Employee employee, string validatorType)
        {
            var employeeValidator = new EmployeeValidator(employeeRespository);
            var validatorReresult = await employeeValidator.DoValidateAsync(employee, validatorType);

            if (!validatorReresult.IsValid)
            {
                throw new DomainException(validatorReresult);
            }
        }
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IEmployeeRespository employeeRespository, IEnumerable <Employee> employees, string validatorType)
        {
            var employeeValidator = new EmployeeValidator(employeeRespository);
            var domainException   = new DomainException();

            foreach (var employee in employees)
            {
                var validatorReresult = await employeeValidator.DoValidateAsync(employee, validatorType);

                if (!validatorReresult.IsValid)
                {
                    domainException.AddErrors(validatorReresult);
                }
            }

            if (domainException.ValidationErrors.ErrorItems.Any())
            {
                throw domainException;
            }
        }
Beispiel #5
0
 public EmployeeService(IEmployeeRespository er)
 {
     this.er = er;
 }
 public EmployeeService(IEmployeeRespository emp)
 {
     _employeeRepo = emp;
 }
Beispiel #7
0
 public HomeController(IEmployeeRespository employeeRespository)
 {
     _employeeRespository = employeeRespository;
 }
 public EmployeeAppService(IEmployeeRespository employeeRespository,
                           IMapper mapper)
 {
     _employeeRespository = employeeRespository;
     _mapper = mapper;
 }
Beispiel #9
0
 public EmployeeController(IEmployeeRespository empRepo)
 {
     employeeRepository = empRepo;
 }
Beispiel #10
0
 public HomeController(IEmployeeRespository employeeRespository, IWebHostEnvironment webHostEnvironment)
 {
     this.employeeRespository = employeeRespository;
     this.webHostEnvironment  = webHostEnvironment;
 }
 public EmployeeControllerTest()
 {
     _service    = new EmployeeRepositoryFake();
     _controller = new EmployeeController(_service);
 }
 public EmployeeController(IEmployeeRespository repo)
 {
     _repo = repo;
 }