Ejemplo n.º 1
0
 /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
 /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
 /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static void BindService(grpc::ServiceBinderBase serviceBinder, OperacaoBase serviceImpl)
 {
     serviceBinder.AddMethod(__Method_Somar, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Calculadora.ParametroRequest, global::Calculadora.ParametroReply>(serviceImpl.Somar));
     serviceBinder.AddMethod(__Method_Dividir, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Calculadora.ParametroRequest, global::Calculadora.ParametroReply>(serviceImpl.Dividir));
     serviceBinder.AddMethod(__Method_Subtrair, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Calculadora.ParametroRequest, global::Calculadora.ParametroReply>(serviceImpl.Subtrair));
     serviceBinder.AddMethod(__Method_Multiplicar, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Calculadora.ParametroRequest, global::Calculadora.ParametroReply>(serviceImpl.Multiplicar));
 }
Ejemplo n.º 2
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(OperacaoBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_Somar, serviceImpl.Somar)
            .AddMethod(__Method_Dividir, serviceImpl.Dividir)
            .AddMethod(__Method_Subtrair, serviceImpl.Subtrair)
            .AddMethod(__Method_Multiplicar, serviceImpl.Multiplicar).Build());
 }
Ejemplo n.º 3
0
 [HttpGet] // api/{controller}
 public IHttpActionResult ObterPorFiltro(string filtro)
 {
     try
     {
         var retorno = OperacaoBase.ObterPorFiltro(filtro);
         return(Ok(retorno.Adapt <IEnumerable <TDTO> >()));
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
 }
Ejemplo n.º 4
0
 [HttpGet] // api/{controller}/{id}
 public IHttpActionResult ObterPorId(int id)
 {
     try
     {
         var retorno = OperacaoBase.ObterPorId(id);
         return(Ok(retorno.Adapt <TDTO>()));
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
 }
Ejemplo n.º 5
0
 [HttpDelete] // api/{controller}
 public IHttpActionResult Excluir(int id)
 {
     try
     {
         var sucesso = OperacaoBase.Excluir(id);
         return(Ok(sucesso));
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
 }
Ejemplo n.º 6
0
        [HttpPut] // api/{controller}
        public IHttpActionResult Atualizar([FromBody] TDTO dto)
        {
            try
            {
                var resultado = ((IValidator)Activator.CreateInstance(typeof(TValidator))).Validate(dto);

                if (resultado.IsValid)
                {
                    var sucesso = OperacaoBase.Atualizar(dto.Adapt <TEntity>());
                    return(Ok(sucesso));
                }
                else
                {
                    return(BadRequest(resultado.ToString()));
                }
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }