diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs index 05e8240..0778cf6 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs @@ -57,15 +57,15 @@ public async Task Details(int id) [HttpGet] - [Route("GetApiUsersByName/{name}")] - public async Task GetApiUsersByName(string name) + [Route("GetApiUsersByRole/{role}")] + public async Task GetApiUsersByName(string role) { - if (string.IsNullOrEmpty(name)) + if (string.IsNullOrEmpty(role)) { _alertService.SetAlertMessage(TempData, "missing_field", false); return RedirectToAction("Index"); } - var response = await _httpCallService.GetDataByName(name); + var response = await _httpCallService.GetDataByRole(role); return Json(response); } diff --git a/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs b/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs index 0593e12..d188b5c 100644 --- a/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs +++ b/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs @@ -19,6 +19,7 @@ public interface IHttpCallService Task GetDataForPrice(int? minPrice, int? maxPrice); Task GetDataBetweenDates(string? startDate, string? endDate); Task GetDataByCityOrAirport(string? city, string? airport); + Task GetDataByRole(string role); Task GetHealthCheck(); string GetModelName(); } diff --git a/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs b/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs index c707c21..420bf95 100644 --- a/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs +++ b/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs @@ -560,6 +560,47 @@ public async Task GetDataByCityOrAirport(string city, string airport) return null; } + /// + /// Gets data of a specified type by role in JSON format. + /// + /// The type of data to retrieve. + /// The role used to filter the data. + /// + /// Returns a JSON string containing the data of type filtered by the specified role. + /// If the retrieval fails, returns null with an error logged. + /// + public async Task GetDataByRole(string role) + { + var modelName = GetModelName(); + + string requestUri = $"{apiURL}/{modelName}"; + if (modelName.Equals("TravelClass")) + { + requestUri += $"es/byRole/{role}"; + } + else + { + requestUri += $"s/byRole/{role}"; + } + + var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); + + using var httpClient = _httpClientFactory.CreateClient("AirportAutomationApi"); + ConfigureHttpClient(httpClient); + + var response = await httpClient.SendAsync(httpRequestMessage); + + if (response.IsSuccessStatusCode) + { + return await response.Content.ReadAsStringAsync(); + } + else + { + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + } + return null; + } + /// /// Creates a new data entry of a specified type. /// diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml index 166d3f7..e146e34 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Airline.AirlineCreateViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Create Airline"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Create Airline

@@ -16,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml index cbd8042..e267243 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Airline.AirlineViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Airline Details"; } -@Html.AntiForgeryToken() -

Airline Details


diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml index 8dbca7c..1d2ef24 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml @@ -1,11 +1,9 @@ @model AirportAutomation.Web.Models.Airline.AirlineViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Airline"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Edit Airline

@@ -13,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml index b0724f8..717e57f 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.ApiUser.ApiUserViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Api User Details"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole == "SuperAdmin") {
diff --git a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml index 2ec2108..58dbc06 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml @@ -1,10 +1,9 @@ @model AirportAutomation.Web.Models.ApiUser.ApiUserViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Api User"; } -@Html.AntiForgeryToken() @if (ViewBag.ApiUserRole == "SuperAdmin") {

Edit Api User

@@ -12,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml index 44616b0..d92f88e 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml @@ -12,8 +12,13 @@ @if (Model != null) {
- - + +
} @@ -89,7 +94,7 @@ else $(document).ready(function () { var searchUrl = '@Url.Action("GetApiUsersByRole", "ApiUser", new { area = "", name = "" })'; var tableBody = $('#tableBody'); - searchByName(searchUrl, tableBody, 'ApiUser'); + searchByRole(searchUrl, tableBody, 'ApiUser'); }); diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml index a968475..b6c94b0 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Destination.DestinationCreateViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Create Destination"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Create Destination

@@ -16,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml index 7c052ba..a8d0bc4 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Destination.DestinationViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Destination Details"; } -@Html.AntiForgeryToken() -

Destination Details


diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml index 358c0f2..8124e5c 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml @@ -1,11 +1,9 @@ @model AirportAutomation.Web.Models.Destination.DestinationViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Destination"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Edit Destination

@@ -13,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml index ec4a8bc..e1fa797 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml @@ -1,19 +1,15 @@ @model AirportAutomation.Web.Models.Flight.FlightCreateViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Create Flight"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Create Flight


+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml index 549336e..df45d56 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Flight.FlightViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Flight Details"; } -@Html.AntiForgeryToken() -

Flight Details


diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml index 6d152c1..1bccf7e 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml @@ -1,16 +1,15 @@ @model AirportAutomation.Web.Models.Flight.FlightViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Flight"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Edit Flight


+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/HealthCheck/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/HealthCheck/Index.cshtml index 625bbb5..644e2a0 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/HealthCheck/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/HealthCheck/Index.cshtml @@ -1,7 +1,7 @@ @model AirportAutomation.Web.Models.HealthCheck.HealthCheckViewModel; @{ - ViewBag.Title = "Health Check"; + ViewBag.Title = "Health Checks"; }
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml index 49f0de7..00f4273 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Passenger.PassengerCreateViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Create Passenger"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Create Passenger

@@ -16,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml index 3161e90..7d95b32 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml @@ -1,13 +1,9 @@ @model AirportAutomation.Web.Models.Passenger.PassengerViewModel; -@{ - ViewData["Title"] = "View"; -} + @{ ViewBag.Title = "Passenger Details"; } -@Html.AntiForgeryToken() -

Passenger Details


diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml index 584aa95..01eeb3b 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml @@ -1,11 +1,9 @@ @model AirportAutomation.Web.Models.Passenger.PassengerViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Passenger"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Edit Passenger

@@ -13,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml index e4417a7..e934871 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.Pilot.PilotCreateViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Create Pilot"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Create Pilot

@@ -16,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml index 6e560cd..6b2f409 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml @@ -1,13 +1,9 @@ @model AirportAutomation.Web.Models.Pilot.PilotViewModel; -@{ - ViewData["Title"] = "View"; -} + @{ ViewBag.Title = "Pilot Details"; } -@Html.AntiForgeryToken() -

Pilot Details


diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml index 01e407e..02a5376 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml @@ -1,11 +1,9 @@ @model AirportAutomation.Web.Models.Pilot.PilotViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Pilot"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Edit Pilot

@@ -13,6 +11,7 @@
+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml index 8718086..e03e6fa 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml @@ -1,6 +1,5 @@ @model PagedResponse - @{ ViewBag.Title = "Pilots"; } diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml index b7028f0..e1e6a63 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml @@ -1,19 +1,15 @@ @model AirportAutomation.Web.Models.PlaneTicket.PlaneTicketCreateViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Create Plane Ticket"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Create Plane Ticket


+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml index 29cac1e..23c2265 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml @@ -1,14 +1,9 @@ @model AirportAutomation.Web.Models.PlaneTicket.PlaneTicketViewModel; -@{ - ViewData["Title"] = "View"; -} @{ ViewBag.Title = "Plane Ticket Details"; } -@Html.AntiForgeryToken() -

Plane Ticket Details


diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml index c25232c..a046ff1 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml @@ -1,16 +1,15 @@ @model AirportAutomation.Web.Models.PlaneTicket.PlaneTicketViewModel; @{ - ViewData["Title"] = "Edit"; + ViewBag.Title = "Edit Plane Ticket"; } -@Html.AntiForgeryToken() - @if (ViewBag.ApiUserRole != "User") {

Edit Plane Ticket


+ @Html.AntiForgeryToken()
diff --git a/AirportAutomation/AirportAutomationWeb/wwwroot/js/SearchHelper.js b/AirportAutomation/AirportAutomationWeb/wwwroot/js/SearchHelper.js index 70c5a77..71b322a 100644 --- a/AirportAutomation/AirportAutomationWeb/wwwroot/js/SearchHelper.js +++ b/AirportAutomation/AirportAutomationWeb/wwwroot/js/SearchHelper.js @@ -204,4 +204,43 @@ function searchByCityOrAirport(searchUrl, tableBody, entityType) { } }); }); +} + +function searchByRole(searchUrl, tableBody, entityType) { + $('#searchButton').click(function () { + var searchTerm = $('#roleSelect').val(); + if (!searchTerm || searchTerm.trim() === '') { + return; + } + + $.ajax({ + url: searchUrl + '/' + searchTerm, + type: 'GET', + success: function (data) { + if (data === null || data.trim() === "") { + showAlertInContainer('No data found for the given search term.', 'danger'); + return; + } + var jsonData = JSON.parse(data); + tableBody.empty(); + + $.each(jsonData.data, function (index, item) { + var row = document.createElement("tr"); + row.innerHTML = '' + item.apiUserId + '' + + '' + item.userName + '' + + '' + item.password + '' + + '' + item.roles + ''; + + row.classList.add("clickable-row"); + row.addEventListener("click", function () { + window.open('/' + entityType + '/' + item.id, '_blank'); + }); + tableBody.append(row); + }); + }, + error: function (error) { + console.error('Error:', error); + } + }); + }); } \ No newline at end of file