Ejemplo n.º 1
0
        public static object CallSelectOrNoSelectMethod(this IDnEspecificacaoBase spec, string methodName, params object[] parameters)
        {
            var paramList = new List <object> {
                spec
            };

            paramList.AddRange(parameters);
            parameters = paramList.ToArray();

            if (spec != null && spec.Servico == null)
            {
                throw new DesenvolvimentoIncorretoException($"The past spec does not have a valid service. See at the time the spec is created if a service has been passed in the spec creator.");
            }

            if (spec is IDnEspecificacaoAlternativa spec2)
            {
                var service = spec2.TipoDeEntidade.GetServiceInstanceByEntity(spec2.Servico.SessaoDaRequisicao);
                var method  = service.GetType().GetMethod($"{methodName}Select");
                if (method == null)
                {
                    throw new DesenvolvimentoIncorretoException($"Method not found: {methodName}Select");
                }

                return(method.MakeGenericMethod(spec2.TipoDeRetorno).Invoke(service, parameters));
            }

            if (spec is IDnEspecificacao spec3)
            {
                var service = spec3.TipoDeEntidade.GetServiceInstanceByEntity(spec3.Servico.SessaoDaRequisicao);
                var method  = service.GetType().GetMethodWithoutAmbiguity(methodName, parameters);
                if (method == null)
                {
                    throw new DesenvolvimentoIncorretoException($"Method not found: {methodName}");
                }

                return(method.Invoke(service, parameters));
            }

            throw new DesenvolvimentoIncorretoException("The specification is of a different type than expected");
        }
Ejemplo n.º 2
0
 public virtual async Task <bool> ExisteAlternativoAsync <TO>(IDnEspecificacaoBase spec)
 {
     return(await GetSpecSelect <TO>(spec).ConverterParaIQueryable(Query).AnyAsync());
 }
Ejemplo n.º 3
0
 public virtual async Task <bool> ExisteAsync(IDnEspecificacaoBase spec)
 {
     return(await GetSpec(spec).ConverterParaIQueryable(Query).AnyAsync());
 }
Ejemplo n.º 4
0
 public static bool Exists(this IDnEspecificacaoBase spec)
 {
     return((bool)spec.Execute(nameof(Exists)));
 }
Ejemplo n.º 5
0
 public static object Execute(this IDnEspecificacaoBase spec, string method, params object[] parameters)
 {
     return(spec.CallSelectOrNoSelectMethod(method, parameters));
 }
Ejemplo n.º 6
0
 public static object FirstOrDefault(this IDnEspecificacaoBase spec)
 {
     return(spec.Execute(nameof(FirstOrDefault)));
 }
Ejemplo n.º 7
0
 public static object List(this IDnEspecificacaoBase spec, DnPaginacao pagination = null)
 {
     return(spec.Execute(nameof(List), new object[] { pagination }));
 }