MVC PivotTable

1

I need to return the result of the procedure, I put a fixed value just to perform my tests but it will have a typed input, in datepick. But I can not create the list for the columns.

Here is the snippet of code:

public string dtaTotal(string dtaini, string dtafinal)
    {

       List<string> dtatot = new List<string>();

       var result = "'" + dtaini + "'" + "," + "'" + dtafinal + "'";

       return result;
    }

    private List<Campanha> BuscaCampanhas()
    {
       using (SqlCommand command = new SqlCommand("exec pr_DashBrokerCampanhas '01-09-2018', '10-09-2018'", DBConnection))
       {
           DBConnection.Open();
           using (SqlDataReader reader = command.ExecuteReader())
           {
               List<Campanha> _listCampanhas = new List<Campanha>();

                  while (reader.Read())
                  {
                      _listCampanhas.Add(

                          new Campanha
                          {
                              DescCampanha = reader["DescCampanha"].ToString(),
                              Total = reader["Total"].ToString(),
                              Columns = dtaTotal()
                          }
                      );
                  }

               DBConnection.Close();
               return _listCampanhas;

           }
       }
    }

Campaign Class:

public class Campanha
{
    public string DescCampanha { get; set; }
    public string Total { get; set; }
    public List<string> Columns { get; set; }
}

public class Dashboard
{
    public List<Envio> Envios { get; set; }
    public List<Broker> Brokers { get; set; }
    public List<Campanha> Campanhas { get; set; }
}

Index controller:

        var DashboardContent = new Dashboard();

        DashboardContent.Envios = BuscaTodosEnvios();
        DashboardContent.Brokers = BuscaBrokers();
        DashboardContent.Campanhas = BuscaCampanhas();

        return View(DashboardContent);
    
asked by anonymous 19.12.2018 / 14:23

1 answer

1

First you need to review your dtaTotal(string dtaini, string dtafinal) function because it expects two parameters that were not passed when you called it in the BuscaCampanhas() method. And, in addition, the dtaTotal method should return a List<string> and is not doing so.

As for receiving the value from the DatePicker field in the Controller, there are several ways to do this. The simplest is through the Model DashboardContent you're sending from Controller to View .

See in this article something that can guide you in your implementation:

    
19.12.2018 / 14:49