How to use a padleft (11) in a get in the API

-3

This is the method I have in my MVC

public async Task<List<FuncionarioViewModel>> GetFuncionariosVM()
        {
            string url = $"http://localhost:56137/api/GetFuncionario";
            var response = await client.GetStringAsync(url);
            var _funcionario = JsonConvert.DeserializeObject<List<FuncionarioViewModel>>(response);   


            return _funcionario;
        }

I need to give m padleft (11) in the CPF field and I do not know how to do it. Below the get method in the API

public class GetFuncionario
    {
        BancoContext banco = new BancoContext();

        //Método que retorna uma lista de funcionarios
        public List<Funcionario> GetFuncionarios()
        {
            return banco.Database.SqlQuery<Funcionario>("sp_cons_funcionarios").ToList();
        }
    }

Because it is a numeric field, I need a padleft (11) for cpf that starts with 0 and cuts the 0 to the left. How do I do this?

    
asked by anonymous 13.08.2018 / 15:04

1 answer

0

You need to create an Employee ViewModel with the same properties as the entity, but in this ViewModel the cpf will be of type string.

In the GetFuncionario method you need to map the Employee entity to the ViewModel Employee, and then in the mapping you give funcionarioViewModel.CPF = funcionario.CPF.ToString().PadLeft(11, "0"); and return that ViewModel to where you want it.

    
13.08.2018 / 17:03