Call PROC MVC to display the list of users who cannot register

Asked

Viewed 60 times

0

Trying to call the PROC sp_UsuariosVariasTentativasCadastro_Result, that brings a list according to the form data. But nothing is happening. Someone can help me ?

NOTE: I created all these "layers" but I don’t know if you have the need.

BLL

public class ListUserBLL: BaseBLL
{
    public List<Usuario> ListarLogUser(int pagina = 0, int linhas = 0)
    {
        if (linhas == 0)
            linhas = int.MaxValue;

        return banco.Usuario
            .AsNoTracking()
            .Where(x => x.FgAtivo == 0)
            .OrderBy(x => x.DsNome)
            .Skip(pagina * linhas)
            .Take(linhas)
            .ToList();
    }
}

Controller

public class ListUserController : Controller
{
    public ListUserModel db = new ListUserModel();

    public ActionResult Index()
    {
        using (var context = new ListUserModel())
        {
            // var data = context.Usuario.SqlQuery<>
            var data = context.DsNome.SqlQuery<Usuario>("exec sp_UsuariosVariasTentativasCadastro_Result").ToList();

            return View(data);
        }          
    }
}

HTML

@model IEnumerable

@{ ViewBag.Title = "ListUser"; Layout = "~/Views/Shared/_Layout.cshtml"; }

<div class="box">
    <div class="box-head">
        <h3 class="box-title">Cadastros não realizados</h3>
        <h6>Lista de usuários que não realizou cadastrado</h6>
        <h6>Quantidade de usuários: @(Model != null && Model.logUser != null ? Model.logUser.Count : 0)</h6>
        <div class="msg  w3-margin-top"></div>
    </div>
    <div class="box-content table-responsive no-padding">
        @if (Model != null) 
        { 
            if (Model.logUser.Count > 0) 
            {
                <table class="table table-hover">
                    <thead>
                        <tr class="w3-light-grey">
                            <th>E-mail</th>
                            <th>Nome</th>
                            <th>Celular</th>
                            <th>Endereço</th>
                        </tr>
                    </thead>

                    @foreach (var item in Model.logUser) 
                    {
                        <tr>
                            <td>@item.DsEmail</td>
                            <td>@item.DsNome</td>
                            <td>@item.DsCelular</td>
                            <td>@item.DsEnderecoCompleto</td>
                        </tr>
                    }
                </table>
            } 
        }
    </div>
</div>

Model

public class ListUserModel
{
    public string DsEmail { get; set; }
    public string DsNome { get; set; }
    public string DsCelular { get; set; }
    public string DsEnderecoCompleto { get; set; }
}

View Model

public class ListUserViewModel
{
    public List<sp_UsuariosVariasTentativasCadastro_Result> logUser { get; set; }
}
  • 1

    but you debugged to see the parameters? because with linhas=0 won’t bring anything because of Take(). Try removing Skip/take and run a test and see if it returns, then remove Where, to make sure that proc returns

  • It didn’t work... he’s not finding my View tbm, I don’t know why...

  • running proc outside the program, in the management studio for example works?

  • @Ricardopunctual works, it brings the list straight.

  • if you are in the same database, proc with the same parameters must return the same. proc has no right parameters? Then banco.Usuario.AsNoTracking().ToList() must return everything

  • Worse than not running because of my controller.. There’s something wrong with it...

  • You can put the SP and the class Usuario in your question? The problem may be there.

  • @Joãomartins, yes I can !

  • @Joãomartins , is that I need to call a list of users who can not register, and this list comes in this process that I’m trying to call.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.