(await CurrentUser());
var phoneModels = _context.PhoneModels.ToList();
+ var selectedExts = pvm?.Extensions == null ? null : myExts.Where(x => pvm.Extensions.Contains(x.Id)).ToList();
ViewBag.MyExtensions = myExts;
- ViewBag.SelectedExtensions = pvm?.Extensions == null ? null : myExts.Where(x => pvm.Extensions.Contains(x.Id)).ToList();
+ ViewBag.SelectedExtensions = selectedExts;
+ ViewBag.PrimaryExtension = selectedExts?.FirstOrDefault(x => x.Id == (pvm.PrimaryExtension ?? -1));
ViewBag.ModelNumbers = phoneModels;
ViewBag.CurrentModel = pvm?.Model == null ? null : phoneModels.Where(m => m.Id == pvm.Model);
}
diff --git a/PhoneToolMX/Views/Phone/_Form.cshtml b/PhoneToolMX/Views/Phone/_Form.cshtml
index aa5e92c..bbc0858 100644
--- a/PhoneToolMX/Views/Phone/_Form.cshtml
+++ b/PhoneToolMX/Views/Phone/_Form.cshtml
@@ -24,6 +24,14 @@
@Html.LabelFor(m => m.Extensions, "Extensions:") |
@Html.ListBoxFor(m => m.Extensions, new MultiSelectList(ViewBag.MyExtensions, "Id", "ListViewName", ViewBag.SelectedExtensions))
+ |
+ @Html.LabelFor(m => m.PrimaryExtension, "Primary Extension:") |
+ @if (ViewBag.SelectedExtensions == null || ((ICollection)ViewBag.SelectedExtensions).Count == 0) {
+ @Html.DropDownListFor(m => m.PrimaryExtension, new List(), "-- No Extensions Selected --", new { @disabled=true })
+ } else {
+ @Html.DropDownListFor(m => m.PrimaryExtension, new SelectList(ViewBag.SelectedExtensions, "Id", "ListViewName", ViewBag.PrimaryExtension), "None")
+ } |
+
diff --git a/PolyProv/Controllers/ConfigController.cs b/PolyProv/Controllers/ConfigController.cs
index 60c2a16..977009c 100644
--- a/PolyProv/Controllers/ConfigController.cs
+++ b/PolyProv/Controllers/ConfigController.cs
@@ -54,6 +54,14 @@ namespace PolyProv.Controllers
public IActionResult PhoneSettings(string addr)
{
var phone = GetByMacStr(addr);
+
+ // ReSharper disable once InvertIf
+ if (phone?.PrimaryExtension is {} primary && phone.Extensions.FirstOrDefault() != primary) {
+ // primary extension exists and is not first, reorder so it's first
+ phone.Extensions.Remove(primary);
+ phone.Extensions = phone.Extensions.Prepend(primary).ToList();
+ }
+
return phone != null ? View("Phone", phone) : NotFound();
}
|