@page
@model webserver.Pages.Manage.RECRUD
@{
    ViewData["Title"] = "RECRUD";
}

<h1>@ViewData["Title"]</h1>

<br>
    <h2>Real Estates List</h2>
    @if(User.IsInRole("Client")==false){
        <a class="btn btn-primary btn-sm" href="/Manage/RealEstateCreation">Create</a>
    }
    <table class="table">
        <thead>
            <tr>
                <th>
                    <form method="get">
                        <input type="hidden" name="pageIndex" value=@Model.index />
                        <input type="hidden" name="pageSize" value=@Model.size />
                        <input type="hidden" name="orderby" value="Name" />
                        <button type="submit" class="btn btn-secondary">Name</button>
                    </form>
                </th>
                <th>
                    <form method="get">
                        <input type="hidden" name="pageIndex" value=@Model.index />
                        <input type="hidden" name="pageSize" value=@Model.size />
                        <input type="hidden" name="orderby" value="Address" />
                        <button type="submit" class="btn btn-secondary">Address</button>
                    </form>
                </th>
                <th>
                    <form method="get">
                        <input type="hidden" name="pageIndex" value=@Model.index />
                        <input type="hidden" name="pageSize" value=@Model.size />
                        <input type="hidden" name="orderby" value="Price" />
                        <button type="submit" class="btn btn-secondary">Price</button>
                    </form>
                </th>
                <th>
                    <form method="get">
                        <input type="hidden" name="pageIndex" value=@Model.index />
                        <input type="hidden" name="pageSize" value=@Model.size />
                        <input type="hidden" name="orderby" value="CompanyId" />
                        <button type="submit" class="btn btn-secondary">Company</button>
                    </form>
                </th>
            </tr>
        </thead>
        <body>
            <li class="item">
                @foreach(var item in Model.listREINFOs){
                    <tr>
                        <td>@item.Name</td>
                        <td>@item.Address</td>
                        <td>@item.Price</td>
                        <td>@item.CompanyName</td>
                        <td>
                            <a asp-page="/Manage/RealEstateUpdate" asp-route-id=@item.Id class="btn btn-success">Up</a>
                        </td>
                        <td>
                            <form asp-page-handler="deleteItem" method="post">
                                <input type="hidden" name="handler" value="DeleteItem" />
                                <input type="hidden" name="id" value=@item.Id />
                                <input type="submit" value="Del" class="btn btn-danger" onclick="return confirm('Are you sure?')" />
                            </form>
                        </td>
                    </tr>
                }
            </li>
        </body>
    </table>
</br>

@{
    int num = (int)Math.Ceiling((float)(Model.rowCount / Model.size)) + 1;
}
<div class="btn-group">
    @for (int i = 1; i <= num && i<10; i++)
    {
        <form method="get" style="margin-right: 2%;">
            <input type="hidden" name="pageIndex" value="@i" />
            <input type="hidden" name="pageSize" value="5" />
            
            @if(Model.index==i){
                <button type="submit" class="btn btn-success">@i</button>
            }else{
                <button type="submit" class="btn btn-primary">@i</button>
            }
        </form>
    }
</div>
