@using CD67.FicheCollege.MVC.Models
@model TerritoireIndexViewModel

@{
    ViewBag.Title = "Liste";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    int maxOrdre = Model.Obj.Count() == 0 ? 0 : Model.Obj.Max(i => i.Ordre);
    int row = 1;
    Territoire modele_territoire = new Territoire();
}

<h2>Liste</h2>

<p>
    <a href="@Url.Action("Create")">
        <span class="glyphicon glyphicon-plus-sign fa-2x color1" style="vertical-align: middle" aria-hidden="true"></span>
        Créer un nouvel élément
    </a>
</p>

<table class="table">
    <tr>
        <th>@Html.DisplayNameFor(model => modele_territoire.Id)</th>
        <th>@Html.DisplayNameFor(model => modele_territoire.Libelle)</th>
        <th>@Html.DisplayNameFor(model => modele_territoire.Referent)</th>
        <th></th>
    </tr>

@foreach (var item in Model.Obj.OrderBy(i=>i.Ordre))
{
    <tr>
        <td>@Html.DisplayFor(modelItem => item.Id)</td>
        <td>@Html.DisplayFor(modelItem => item.Libelle)</td>
        <td>@Html.DisplayFor(modelItem => item.Referent)</td>
        <td>
            @if (row != 1)
                {
                <a href="@Url.Action("Up", new { id = item.Id })">
                    <span class="glyphicon glyphicon-circle-arrow-up fa-2x color1" title="Remonter" style="vertical-align: middle" aria-hidden="true"></span>
                </a>
            }
            else
            {
                <span class="glyphicon glyphicon-circle-arrow-up fa-2x color2" title="Remonter" style="vertical-align: middle" aria-hidden="true"></span>
            }
            @if (item.Ordre != maxOrdre)
                {
                <a href="@Url.Action("Down", new { id = item.Id })">
                    <span class="glyphicon glyphicon-circle-arrow-down fa-2x color1" title="Descendre" style="vertical-align: middle" aria-hidden="true"></span>
                </a>
            }
            else
            {
                <span class="glyphicon glyphicon-circle-arrow-down fa-2x color2" title="Descendre" style="vertical-align: middle" aria-hidden="true"></span>
            }
            <a href="@Url.Action("Edit", new { id = item.Id })">
                <span class="glyphicon glyphicon-edit fa-2x color1" title="Modifier" style="vertical-align: middle" aria-hidden="true"></span>
            </a>
            <a href="@Url.Action("Delete", new { id = item.Id })">
                <span class="glyphicon glyphicon-remove-sign fa-2x color1" title="Supprimer" style="vertical-align: middle" aria-hidden="true"></span>
            </a>
        </td>
    </tr>
    row += 1;
}

</table>
