Exemplo n.º 1
0
 public BookService(IBookRepository repository,
                    IMapper mapper,
                    IUnitOfWork unitOfWork,
                    IBaseValidator <BookDto> validator)
 {
     this.repository = repository;
     this.mapper     = mapper;
     this.unitOfWork = unitOfWork;
     this.validator  = validator;
 }
        protected BaseRepository(TDbContext dbContext,
                                 IBaseValidator <TEntity> validator,
                                 IMapper mapper)
        {
            Contract.Requires(dbContext != null);
            Contract.Requires(validator != null);
            Contract.Requires(mapper != null);

            this.dbContext = dbContext;
            this.validator = validator;
            this.mapper    = mapper;
        }
 public static ValidationErrorModel BuildValidationErrorModel(SupplementaryDataModel model, IBaseValidator validator)
 {
     return(new ValidationErrorModel
     {
         RuleName = validator.ErrorName,
         ErrorMessage = validator.ErrorMessage,
         IsWarning = validator.IsWarning,
         ConRefNumber = model.ConRefNumber,
         DeliverableCode = model.DeliverableCode,
         CalendarYear = model.CalendarYear.ToString(),
         CalendarMonth = model.CalendarMonth.ToString(),
         CostType = model.CostType,
         StaffName = model.StaffName,
         ProviderSpecifiedReference = model.ProviderSpecifiedReference,
         ULN = model.ULN.ToString(),
         ReferenceType = model.ReferenceType,
         Reference = model.Reference,
         ProjectHours = model.ProjectHours.ToString(),
         OrgHours = model.OrgHours.ToString(),
         TotalHoursWorked = model.TotalHoursWorked.ToString(),
         HourlyRate = model.HourlyRate.ToString(),
         Value = model.Value.ToString()
     });
 }
Exemplo n.º 4
0
        private void ValidateBeforeProceeding(IInvocation invocation)
        {
            //le invocation vas être destiné (target) a un IBaseValidatedAppService, car dans le ValidationRegistrar dans la méthode Kernel_ComponentRegistered
            //seulement les IBaseRestApplicationService sont handle par l'Interceptor.
            IBaseValidatedAppService appService = invocation.InvocationTarget as IBaseValidatedAppService;

            string assemblyName = invocation.InvocationTarget.GetType().BaseType.Assembly.ManifestModule.Name.Replace(".dll", ".");

            string validatorName = "I" + appService.GetType().BaseType.Name + "Validator";

            TypeResolver typeResolver = _iocResolver.Resolve <TypeResolver>();

            Type validatorInterfaceType = typeResolver[assemblyName + validatorName];

            if (validatorInterfaceType is null)
            {
                return;
            }

            IBaseValidator baseValidator = _iocResolver.Resolve(validatorInterfaceType) as IBaseValidator;

            Type validatorType = baseValidator.GetType();

            //IocManager.Instance.IocContainer.Resolve("");
            //on vas essayer d'aller chercher par réflection les méthode de validation
            //on vas devoir avoir un standard que les méthode dans les Validator qui hérite de IBaseValidation
            //doivent avoir le même nom que la méthode du app service qu'elle valide plus le terme Validation
            string methodName = invocation.MethodInvocationTarget.Name + "Validation";

            MethodInfo method = validatorType.GetMethod(methodName);

            if (method != null)
            {
                //on invoke la méthode du validator
                //on doit faire le try catch et le re-throw ici sinon on perdait le type de l'exception
                try
                {
                    if (InternalAsyncHelper.IsAsyncMethod(method))
                    {
                        var returnValue = method.Invoke(baseValidator, invocation.Arguments);
                        ////Wait task execution and modify return value
                        if (method.ReturnType == typeof(Task))
                        {
                            returnValue = InternalAsyncHelper.AwaitTaskWithFinally(
                                (Task)returnValue,
                                ex =>
                            {
                                invocation.Proceed();
                            });
                        }
                        else //Task<TResult>
                        {
                            returnValue = InternalAsyncHelper.CallAwaitTaskWithFinallyAndGetResult(
                                method.ReturnType.GenericTypeArguments[0],
                                returnValue,
                                ex =>
                            {
                                invocation.Proceed();
                            });
                        }
                    }
                    else
                    {
                        invocation.Proceed();
                    }
                }
                catch (Exception ex)
                {
                    throw ex.InnerException;
                }
            }
            else
            {
            }
        }
Exemplo n.º 5
0
 public BaseManager(IUnitOfWork unitOfWork, IBaseValidator <TViewModel> validator)
 {
     UnitOfWork = unitOfWork;
     Validator  = validator;
 }
 public static ValidationErrorModel BuildValidationErrorModel(SupplementaryDataModel model, IBaseValidator validator)
 {
     return(new ValidationErrorModel
     {
         RuleName = validator.ErrorName,
         ErrorMessage = validator.ErrorMessage,
         IsWarning = validator.IsWarning,
         ConRefNumber = model.ConRefNumber,
         DeliverableCode = model.DeliverableCode,
         CalendarYear = model.CalendarYear.ToString(),
         CalendarMonth = model.CalendarMonth.ToString(),
         CostType = model.CostType,
         ProviderSpecifiedReference = model.ProviderSpecifiedReference,
         ULN = model.ULN.ToString(),
         ReferenceType = model.ReferenceType,
         Reference = model.Reference,
         LearnAimRef = model.LearnAimRef,
         SupplementaryDataPanelDate = model.SupplementaryDataPanelDate?.ToString("dd/MM/yyyy"),
         Value = model.Value.ToString()
     });
 }
Exemplo n.º 7
0
 public GameDetailsController(IBaseValidator stringValidator, IClient <Games> client)
 {
     this.stringValidator = stringValidator ?? throw new ArgumentNullException(nameof(stringValidator));
     this.client          = client ?? throw new ArgumentNullException(nameof(client));
 }