Creating a collection

1

The two images are how my array is. In the first image I have an array with 3 items, the first of the month of April and contains 4 passages. For each ticket I have the respective participants. My problem is in sending this array to my view , because I can not get some properties at runtime as passagem.participante .

I tried to break this down into three arrays , but when I run via foreach on the screen it does not display properly with the month and its participants with their passages.

How to make an array only that I could access all properties and play them on the screen?

Here's how the view looks today, but I need to sync the information as I said earlier.

@using WebProvider.BMW_Incentivo.Domain.Models
@model WebProvider.BMW_Incentivo.Admin.Models.GerenciaPassagemModel

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

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/css/pageDataTables.css")" media="screen" />
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/css/tableDataTables.css")" media="screen" />
<script src="@Url.Content("~/Content/js/jquery.dataTables.js")" type="text/javascript"></script>
<script src="~/Content/js/pages/GerenciadorPassagem.js"></script>

@using (Html.BeginForm("Index", "GerenciaPassagem", FormMethod.Post))
{
    <fieldset id="passagem">

        <div style="float: left;">
            <label>Mês:</label>

            <select id="ListaPeriodo" name="ListaPeriodo" onchange="listaPassagensMes();">
                @foreach (var item in Model.ListaPeriodo)
                {
                    <option id="@item.Mes" value="@item.Mes">@item.DescricaoMes</option>
                }
            </select>

            <span class="error">* Campo Obrigatório</span>

        </div>
        <div style="float: right;">
            <label>Ano:</label>

            <select id="ListaAno" name="ListaAno">

                @*@foreach (int item in Model.Ano)
                {*@
                    <option id="@Model.Ano " value="@Model.Ano "> @Model.Ano</option>

                @*}*@
            </select>



            <span class="error">* Campo Obrigatório</span>

        </div>
        <table border="2" class="data display datatable" id="tabFiltra">

            <thead>
                <tr>
                    <th><span>Acao</span></th>
                    <th><span>Participante - CPF</span></th>
                    <th><span>Passagem</span></th>
                    <th><span>Status</span></th>
                </tr>
            </thead>

            <tbody>
                @foreach (Passagem participante in Model.ListaParticipante)
                {
                    <tr>
                        <td>
                            <input type="checkbox" id="@participante.Id" name="idsCredito" value="participante.Acao" @(participante.Acao == true || participante.Acao == false ? "checked = 'checked' readonly='readonly' " : string.Empty) />
                        </td>
                        <td>

                            <label id="@participante.Participante.Id" for="participanteId"> @(participante.Passagens != null ? participante.Participante.NomeCompleto + " - " + participante.Participante.CPF : "") </label>
                        </td>
                        <td>
                            <label id="@participante.Passagens" for="participantePassagem">@(participante.Passagens.ToString() != "" ? participante.Passagens.ToString() : "") </label>

                        </td>
                        <td>

                            <label id="@participante.Acao" for="participanteAcao">@(participante.Acao == true ? "Aprovado" : participante.Acao == false ? "Recusado" : "-")</label>

                        </td>
                    </tr>
                }
            </tbody>

        </table>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />

        <input type="button" value="Aprovar" id="btAprovar" onclick="Aprovar(); return false;" onblur="Reload();" style="margin-left: 9px;" />

        <input type="button" value="Recusar" id="BtRecusar" onclick="Reprovar(); return false;" style="margin-left: 9px;" />

    </fieldset>
}

@section Scripts {
    @Scripts.Render("~/bundles/knockout")
    @Scripts.Render("~/bundles/jqueryui")
}
    
asked by anonymous 12.04.2014 / 03:42

2 answers

1

Turn these methods into your ViewModel on properties that are consuming the IEnumerable Period that was set by the Controller

For example (ViewModel class: MobilityModel )

private IEnumerable<Periodo> listaPeriodo_
public IEnumerable<Periodo> ListaPeriodo { 
   get { return this.listaPeriodo_; } 
   set { this.listaPeriodo_ = value; } //Seta pelo Controller
}

public IEnumerable<int> ListaAno {
   get { 
       foreach (Periodo p in listaPeriodo_)
       {
           yield p.Ano;
       }
   }
}

public IEnumerable<Passagem> ListaParticipante {
   get { 
       foreach (Periodo p in listaPeriodo_)
       {
           for each (Passagem ps in p.Passagem)
               yield ps;
       }
   }
}

In your view, you should use:

@foreach (Passagem participante in Model.ListaParticipante.Distinct())
@foreach (int ano in Model.ListaAno.Distinct().OrderBy(p => p))
@foreach (Periodo periodo in Model.ListaPeriodo)
    
12.04.2014 / 15:32
-1

It does not seem to be a View problem: it's just a feature of the Entity Framework, which does not load participants alone because it's a nesting level greater than 1, (level 1), but does not load aggregate pass data (level 2 or more).

I do not know how your code is in the Controller , but I would recommend using the .Include() method to force the aggregate data load. For example:

var gerenciaPassagens = context.GerenciaPassagensModels
    .Include(gp => gp.Passagem.Participante)
    .Where(/* Seus parâmetros para carga das informações */)

return View(gerenciaPassagens);
    
12.04.2014 / 19:44