Пример #1
0
 public UnitGroupBusiness(
     IUnitGroupDataAccess materialDataAccess,
     IMapper mapper,
     IValidator <UnitGroupApiModel> validator
     )
 {
     _unitGroupDataAccess = materialDataAccess;
     _mapper    = mapper;
     _validator = validator;
 }
Пример #2
0
        public UnitValidation(
            IUnitDataAccess unitDataAccess,
            IUnitGroupDataAccess unitGroupDataAccess)
        {
            _unitDataAccess      = unitDataAccess;
            _unitGroupDataAccess = unitGroupDataAccess;

            RuleSet(string.Join(",",
                                Enum.GetName(typeof(UnitRuleSet), UnitRuleSet.Create),
                                Enum.GetName(typeof(UnitRuleSet), UnitRuleSet.Update)),
                    () => {
                RuleFor(unit => unit.Title).NotNull().NotEmpty().WithMessage($"{TitleName} do {entityName} não pode estar vazio");
                RuleFor(unit => unit.Title).Length(TitleMin, TitleMax).WithMessage($"{TitleName} do {entityName} precisa ter entre {TitleMin} e {TitleMax} caracteres");
                RuleFor(unit => unit.Title).Must(TitleNotAlreadyExists).WithMessage($"{TitleName} do {entityName} já existe");

                RuleFor(unit => unit.Abbreviation).NotNull().NotEmpty().WithMessage($"{AbbreviationName} do {entityName} não pode estar vazio");
                RuleFor(unit => unit.Abbreviation).Length(AbbreviationMin, AbbreviationMax).WithMessage($"{AbbreviationName} do {entityName} precisa ter entre {AbbreviationMin} e {AbbreviationMax} caracteres");
                RuleFor(unit => unit.Abbreviation).Must(AbbreviationNotAlreadyExists).WithMessage($"{AbbreviationName} do {entityName} já existe");

                RuleFor(unit => unit.IdGroup).GreaterThan(0).WithMessage($"{IdGroupName} do {entityName} não pode estar vazio");
                RuleFor(unit => unit.IdGroup).Must(IdGroupAlreadyExists).WithMessage($"{IdGroupName} do {entityName} não existe");

                When(unit => unit.ReferenceUnit.HasValue && unit.ReferenceUnit.Value != 0, () =>
                {
                    RuleFor(unit => unit.ReferenceUnit.Value).Must(IdAlreadyExists).WithMessage($"{ReferenceUnitName} do {entityName} não existe");

                    RuleFor(unit => unit.ReferenceValue).GreaterThan(0).WithMessage($"{ReferenceValueName} do {entityName} tem que ser maior que zero");
                }).Otherwise(() =>
                {
                    RuleFor(unit => unit.ReferenceValue).Equal(1).WithMessage($"{ReferenceValueName} do {entityName} precisa ser 1.0 caso não tenha unidade de referência");
                });
            });

            RuleSet(string.Join(",",
                                Enum.GetName(typeof(UnitRuleSet), UnitRuleSet.Delete),
                                Enum.GetName(typeof(UnitRuleSet), UnitRuleSet.Update)),
                    () => {
                RuleFor(unit => unit.Id).GreaterThan(0).WithMessage($"{IdName} do {entityName} não pode estar vazio");
                RuleFor(unit => unit.Id).Must(IdAlreadyExists).WithMessage($"{IdName} do {entityName} não existe");
            });
        }
Пример #3
0
        public UnitGroupValidation(IUnitGroupDataAccess unitGroupDataAccess)
        {
            _unitGroupDataAccess = unitGroupDataAccess;

            RuleSet(string.Join(",",
                                Enum.GetName(typeof(UnitGroupRuleSet), UnitGroupRuleSet.Create),
                                Enum.GetName(typeof(UnitGroupRuleSet), UnitGroupRuleSet.Update)),
                    () => {
                RuleFor(unitGroup => unitGroup.Title).NotNull().NotEmpty().WithMessage($"{TitleName} do {entityName} não pode estar vazio");
                RuleFor(unitGroup => unitGroup.Title).Length(TitleMin, TitleMax).WithMessage($"{TitleName} do {entityName} precisa ter entre {TitleMin} e {TitleMax} caracteres");
                RuleFor(unitGroup => unitGroup.Title).Must(TitleNotAlreadyExists).WithMessage($"{TitleName} do {entityName} já existe");
            });

            RuleSet(string.Join(",",
                                Enum.GetName(typeof(UnitGroupRuleSet), UnitGroupRuleSet.Delete),
                                Enum.GetName(typeof(UnitGroupRuleSet), UnitGroupRuleSet.Update)),
                    () => {
                RuleFor(unitGroup => unitGroup.Id).GreaterThan(0).WithMessage($"{IdName} do {entityName} não pode estar vazio");
                RuleFor(unitGroup => unitGroup.Id).Must(AlreadyExists).WithMessage($"{IdName} do {entityName} não existe");
            });
        }