@model IEnumerable<ServiceCenter.Data.CastleActiveRecord.Request>

<p>
    @Html.ActionLink("Назад к списку всех заявок", "Index", null, new { @class = "button alt small" })
</p>
<table class="alt">
    <thead>
        <tr>
            <th style="text-align:center;">Дата приёма/выдачи</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().DeviceType)</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().Manufacturer)</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().Model)</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().Description)</th>
            <th style="text-align:center;">Клиент</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().Cost)</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().Status)</th>
            <th style="text-align:center;">@Html.LabelFor(x => x.FirstOrDefault().Comment)</th>
            <th>Действия</th>
        </tr>
    </thead>
    
@foreach (var item in Model) {
    <tr>
    @if (item.DateOut.HasValue)
    { 
        <td style="text-align:center;">@string.Format("{0:dd.MM.yyyy} / {1:dd.MM.yyyy}", item.DateIn, item.DateOut.Value)</td>
    }
    else
    { 
        <td style="text-align:center;">@item.DateIn.ToShortDateString()</td>
    }
        <td style="text-align:center;">@item.DeviceType.Value</td>
        <td style="text-align:center;">@Html.ActionLink(item.Manufacturer.Value, "Manufacturer", new { id = item.Manufacturer.Id })</td>
        <td>@item.Model</td>
        <td>@item.Description</td>
    @if (!string.IsNullOrEmpty(item.ClientPhone))
    { 
        <td>@string.Format("{0}, {1}", item.ClientName, item.ClientPhone)</td>
    }
    else
    { 
        <td>@item.ClientName</td>
    }
        <td style="text-align:center;">@item.Cost</td>
        <td style="text-align:center;">@Html.ActionLink(item.Status.Value, "Status", new { id = item.Status.Id })</td>
        <td>@item.Comment</td>
        <td>
            @Html.ActionLink("Редактировать", "Edit", new { id = item.Id })
            <br />
            @Html.ActionLink("Удалить", "Delete", new { id = item.Id })
        </td>
    </tr>
}
    
</table>
<div style="text-align:right; width: 100%;">Всего элементов: @Model.Count()</div>