MICHELE: CHIAMATE/ IMPIANTI

This commit is contained in:
michele 2023-10-16 14:52:40 +02:00
parent 4234c6b4f1
commit 16539d257c
3 changed files with 43 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Text;
@ -82,6 +83,7 @@ namespace VirtualTask.Controllers
public IActionResult Create()
{
ViewBag.AllStockList = LoadStockItems();
return View();
}
@ -115,7 +117,7 @@ namespace VirtualTask.Controllers
return RedirectToAction("Error");
}
return View();
//return View();
}
#endregion CREATE
@ -129,7 +131,7 @@ namespace VirtualTask.Controllers
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "chiamate";
urlBase = apiUrl + "chiamateList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
@ -168,7 +170,7 @@ namespace VirtualTask.Controllers
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "chiamate";
urlBase = apiUrl + "chiamateList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
@ -193,6 +195,7 @@ namespace VirtualTask.Controllers
return RedirectToAction("Error");
}
ViewBag.AllStockList = LoadStockItems();
return View(chiamata);
}
@ -244,7 +247,7 @@ namespace VirtualTask.Controllers
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "chiamate";
urlBase = apiUrl + "chiamateList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
@ -302,6 +305,34 @@ namespace VirtualTask.Controllers
}
#endregion DELETE
private List<SelectListItem> LoadStockItems()
{
SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "impiantiList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
List<SelectListItem> selectItems = new List<SelectListItem>();
List<Impianto> modelList = new List<Impianto>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<Impianto>>(data);
foreach (var role in modelList)
{
SelectListItem listItem = new SelectListItem();
listItem.Value = role.imcodimp;
listItem.Text = role.imdescri;
selectItems.Add(listItem);
}
}
return selectItems;
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@ -230,7 +230,7 @@ namespace VirtualTask.Controllers
return RedirectToAction("Error");
}
//return View(model);
return View(model);
}
#endregion EDIT

View File

@ -70,7 +70,8 @@
</div>
<div class="form-group">
<label asp-for="chcodimp" class="control-label"></label>
<input asp-for="chcodimp" class="form-control" />
@*<input asp-for="chcodimp" class="form-control" />*@
@Html.DropDownListFor(x => x.chcodimp,(IEnumerable<SelectListItem>)ViewBag.AllStockList, new {@class = "form-control"})
<span asp-validation-for="chcodimp" class="text-danger"></span>
</div>
<div class="form-group">
@ -310,6 +311,11 @@
</div>
</div>
<script type="text/javascript">
$(function () {
$("#chcodimp").select2();
});
</script>
<div>
<a asp-action="Index">Back to List</a>
</div>