diff --git a/AirportAutomation/AirportAutomationApi.Test/Controllers/ApiUserManagementControllerTests.cs b/AirportAutomation/AirportAutomationApi.Test/Controllers/ApiUsersControllerTests.cs similarity index 96% rename from AirportAutomation/AirportAutomationApi.Test/Controllers/ApiUserManagementControllerTests.cs rename to AirportAutomation/AirportAutomationApi.Test/Controllers/ApiUsersControllerTests.cs index b571608..d3e2a61 100644 --- a/AirportAutomation/AirportAutomationApi.Test/Controllers/ApiUserManagementControllerTests.cs +++ b/AirportAutomation/AirportAutomationApi.Test/Controllers/ApiUsersControllerTests.cs @@ -14,15 +14,15 @@ namespace AirportAutomationApi.Test.Controllers { - public class ApiUserManagementControllerTests + public class ApiUsersControllerTests { - private readonly ApiUserManagementController _controller; - private readonly Mock _apiUserServiceMock; + private readonly ApiUsersController _controller; + private readonly Mock _apiUserServiceMock; private readonly Mock _paginationValidationServiceMock; private readonly Mock _inputValidationServiceMock; private readonly Mock _utilityServiceMock; private readonly Mock _mapperMock; - private readonly Mock> _loggerMock; + private readonly Mock> _loggerMock; private readonly Mock _configurationMock; private readonly ApiUserEntity apiUserEntity = new() @@ -40,14 +40,14 @@ public class ApiUserManagementControllerTests Roles = "SuperAdmin" }; - public ApiUserManagementControllerTests() + public ApiUsersControllerTests() { - _apiUserServiceMock = new Mock(); + _apiUserServiceMock = new Mock(); _paginationValidationServiceMock = new Mock(); _inputValidationServiceMock = new Mock(); _utilityServiceMock = new Mock(); _mapperMock = new Mock(); - _loggerMock = new Mock>(); + _loggerMock = new Mock>(); _configurationMock = new Mock(); var configBuilder = new ConfigurationBuilder(); configBuilder.AddInMemoryCollection(new Dictionary @@ -57,7 +57,7 @@ public ApiUserManagementControllerTests() _configurationMock.Setup(x => x.GetSection(It.IsAny())) .Returns(configBuilder.Build().GetSection("")); - _controller = new ApiUserManagementController( + _controller = new ApiUsersController( _apiUserServiceMock.Object, _paginationValidationServiceMock.Object, _inputValidationServiceMock.Object, @@ -420,7 +420,7 @@ public async Task PutApiUser_ReturnsNoContent_WhenUpdateIsSuccessful() { // Arrange int id = 1; - var apiUserRoleDto = new ApiUserRoleDto { Id = id }; + var apiUserRoleDto = new ApiUserRoleDto { ApiUserId = id }; var apiUserEntity = new ApiUserEntity { ApiUserId = id }; _inputValidationServiceMock.Setup(service => service.IsNonNegativeInt(id)).Returns(true); @@ -441,7 +441,7 @@ public async Task PutApiUser_ReturnsBadRequest_WhenIdIsInvalid() { // Arrange int invalidId = -1; - var apiUserRoleDto = new ApiUserRoleDto { Id = invalidId }; + var apiUserRoleDto = new ApiUserRoleDto { ApiUserId = invalidId }; _inputValidationServiceMock.Setup(service => service.IsNonNegativeInt(invalidId)).Returns(false); @@ -459,7 +459,7 @@ public async Task PutApiUser_ReturnsBadRequest_WhenIdInDtoDoesNotMatchIdInUrl() { // Arrange int id = 1; - var apiUserRoleDto = new ApiUserRoleDto { Id = 2 }; + var apiUserRoleDto = new ApiUserRoleDto { ApiUserId = 2 }; _inputValidationServiceMock.Setup(service => service.IsNonNegativeInt(id)).Returns(true); @@ -476,7 +476,7 @@ public async Task PutApiUser_ReturnsNotFound_WhenApiUserDoesNotExist() { // Arrange int id = 1; - var apiUserRoleDto = new ApiUserRoleDto { Id = id }; + var apiUserRoleDto = new ApiUserRoleDto { ApiUserId = id }; _inputValidationServiceMock.Setup(service => service.IsNonNegativeInt(id)).Returns(true); _apiUserServiceMock.Setup(service => service.ApiUserExists(id)).ReturnsAsync(false); diff --git a/AirportAutomation/AirportAutomationApi.Test/Services/ApiUserManagementServiceTests.cs b/AirportAutomation/AirportAutomationApi.Test/Services/ApiUserServiceTests.cs similarity index 84% rename from AirportAutomation/AirportAutomationApi.Test/Services/ApiUserManagementServiceTests.cs rename to AirportAutomation/AirportAutomationApi.Test/Services/ApiUserServiceTests.cs index e6403d3..a0ceb3c 100644 --- a/AirportAutomation/AirportAutomationApi.Test/Services/ApiUserManagementServiceTests.cs +++ b/AirportAutomation/AirportAutomationApi.Test/Services/ApiUserServiceTests.cs @@ -6,15 +6,15 @@ namespace AirportAutomationApi.Test.Services { - public class ApiUserManagementServiceTests + public class ApiUserServiceTests { - private readonly Mock _repositoryMock; - private readonly ApiUserManagementService _service; + private readonly Mock _repositoryMock; + private readonly ApiUserService _service; - public ApiUserManagementServiceTests() + public ApiUserServiceTests() { - _repositoryMock = new Mock(); - _service = new ApiUserManagementService(_repositoryMock.Object); + _repositoryMock = new Mock(); + _service = new ApiUserService(_repositoryMock.Object); } [Fact] diff --git a/AirportAutomation/AirportAutomationApplication/Dtos/ApiUser/ApiUserRoleDto.cs b/AirportAutomation/AirportAutomationApplication/Dtos/ApiUser/ApiUserRoleDto.cs index acff909..b63dc2f 100644 --- a/AirportAutomation/AirportAutomationApplication/Dtos/ApiUser/ApiUserRoleDto.cs +++ b/AirportAutomation/AirportAutomationApplication/Dtos/ApiUser/ApiUserRoleDto.cs @@ -4,7 +4,7 @@ namespace AirportAutomation.Application.Dtos.ApiUser; public class ApiUserRoleDto { - public int Id { get; set; } + public int ApiUserId { get; set; } [Required(ErrorMessage = "User Name is required.")] [MaxLength(50, ErrorMessage = "User Name cannot be longer than 50 characters.")] diff --git a/AirportAutomation/AirportAutomationApplication/Services/ApiUserManagementService.cs b/AirportAutomation/AirportAutomationApplication/Services/ApiUserService.cs similarity index 84% rename from AirportAutomation/AirportAutomationApplication/Services/ApiUserManagementService.cs rename to AirportAutomation/AirportAutomationApplication/Services/ApiUserService.cs index f4b5a96..6b2fa95 100644 --- a/AirportAutomation/AirportAutomationApplication/Services/ApiUserManagementService.cs +++ b/AirportAutomation/AirportAutomationApplication/Services/ApiUserService.cs @@ -4,12 +4,12 @@ namespace AirportAutomation.Application.Services { - public class ApiUserManagementService : IApiUserManagementService + public class ApiUserService : IApiUserService { - private readonly IApiUserManagementRepository _apiUserManagementRepository; + private readonly IApiUserRepository _apiUserManagementRepository; - public ApiUserManagementService(IApiUserManagementRepository apiUserManagementRepository) + public ApiUserService(IApiUserRepository apiUserManagementRepository) { _apiUserManagementRepository = apiUserManagementRepository; } diff --git a/AirportAutomation/AirportAutomationDomain/Interfaces/IRepositories/IApiUserManagementRepository.cs b/AirportAutomation/AirportAutomationDomain/Interfaces/IRepositories/IApiUserRepository.cs similarity index 90% rename from AirportAutomation/AirportAutomationDomain/Interfaces/IRepositories/IApiUserManagementRepository.cs rename to AirportAutomation/AirportAutomationDomain/Interfaces/IRepositories/IApiUserRepository.cs index f8bbd4c..7a0ad63 100644 --- a/AirportAutomation/AirportAutomationDomain/Interfaces/IRepositories/IApiUserManagementRepository.cs +++ b/AirportAutomation/AirportAutomationDomain/Interfaces/IRepositories/IApiUserRepository.cs @@ -2,7 +2,7 @@ namespace AirportAutomation.Core.Interfaces.IRepositories { - public interface IApiUserManagementRepository + public interface IApiUserRepository { Task> GetApiUsers(int page, int pageSize); Task GetApiUser(int id); diff --git a/AirportAutomation/AirportAutomationDomain/Interfaces/IServices/IApiUserManagementService.cs b/AirportAutomation/AirportAutomationDomain/Interfaces/IServices/IApiUserService.cs similarity index 91% rename from AirportAutomation/AirportAutomationDomain/Interfaces/IServices/IApiUserManagementService.cs rename to AirportAutomation/AirportAutomationDomain/Interfaces/IServices/IApiUserService.cs index 6c8b7da..da470e8 100644 --- a/AirportAutomation/AirportAutomationDomain/Interfaces/IServices/IApiUserManagementService.cs +++ b/AirportAutomation/AirportAutomationDomain/Interfaces/IServices/IApiUserService.cs @@ -2,7 +2,7 @@ namespace AirportAutomation.Core.Interfaces.IServices { - public interface IApiUserManagementService + public interface IApiUserService { Task> GetApiUsers(int page, int pageSize); Task GetApiUser(int id); diff --git a/AirportAutomation/AirportAutomationInfrastructure/Repositories/ApiUserManagementRepository.cs b/AirportAutomation/AirportAutomationInfrastructure/Repositories/ApiUserRepository.cs similarity index 92% rename from AirportAutomation/AirportAutomationInfrastructure/Repositories/ApiUserManagementRepository.cs rename to AirportAutomation/AirportAutomationInfrastructure/Repositories/ApiUserRepository.cs index 446cac5..c523213 100644 --- a/AirportAutomation/AirportAutomationInfrastructure/Repositories/ApiUserManagementRepository.cs +++ b/AirportAutomation/AirportAutomationInfrastructure/Repositories/ApiUserRepository.cs @@ -5,11 +5,11 @@ namespace AirportAutomation.Infrastructure.Repositories { - public class ApiUserManagementRepository : IApiUserManagementRepository + public class ApiUserRepository : IApiUserRepository { protected readonly DatabaseContext _context; - public ApiUserManagementRepository(DatabaseContext context) + public ApiUserRepository(DatabaseContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); } diff --git a/AirportAutomation/AirportAutomationWeb/AirportAutomation.Web.csproj b/AirportAutomation/AirportAutomationWeb/AirportAutomation.Web.csproj index e6ff9eb..6661021 100644 --- a/AirportAutomation/AirportAutomationWeb/AirportAutomation.Web.csproj +++ b/AirportAutomation/AirportAutomationWeb/AirportAutomation.Web.csproj @@ -10,6 +10,7 @@ + @@ -17,6 +18,7 @@ + diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/AirlineController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/AirlineController.cs index 4cc07ec..3135c65 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/AirlineController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/AirlineController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class AirlineController : Controller + public class AirlineController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs new file mode 100644 index 0000000..05e8240 --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs @@ -0,0 +1,136 @@ +using AirportAutomation.Application.Dtos.ApiUser; +using AirportAutomation.Core.Entities; +using AirportAutomation.Web.Interfaces; +using AirportAutomation.Web.Models.ApiUser; +using AirportAutomation.Web.Models.Response; +using AutoMapper; +using Microsoft.AspNetCore.Mvc; + +namespace AirportAutomation.Web.Controllers +{ + [Route("[controller]")] + public class ApiUserController : BaseController + { + private readonly IHttpCallService _httpCallService; + private readonly IAlertService _alertService; + private readonly IMapper _mapper; + + public ApiUserController(IHttpCallService httpCallService, IAlertService alertService, IMapper mapper) + { + _httpCallService = httpCallService; + _alertService = alertService; + _mapper = mapper; + } + + [HttpGet] + public async Task Index(int page = 1, int pageSize = 10) + { + if (page < 1) + { + _alertService.SetAlertMessage(TempData, "invalid_page_number", false); + return RedirectToAction("Index"); + } + var response = await _httpCallService.GetDataList(page, pageSize); + if (response == null) + { + return View(); + } + var pagedResponse = _mapper.Map>(response); + return View(pagedResponse); + } + + [HttpGet] + [Route("{id}")] + public async Task Details(int id) + { + var response = await _httpCallService.GetData(id); + if (response is null) + { + _alertService.SetAlertMessage(TempData, "data_not_found", false); + return RedirectToAction("Index"); + } + else + { + return View(_mapper.Map(response)); + } + } + + + [HttpGet] + [Route("GetApiUsersByName/{name}")] + public async Task GetApiUsersByName(string name) + { + if (string.IsNullOrEmpty(name)) + { + _alertService.SetAlertMessage(TempData, "missing_field", false); + return RedirectToAction("Index"); + } + var response = await _httpCallService.GetDataByName(name); + return Json(response); + } + + [HttpGet] + [Route("Create")] + public IActionResult Create() + { + return View(); + } + + [HttpGet] + [Route("Edit/{id}")] + public async Task Edit(int id) + { + var response = await _httpCallService.GetData(id); + if (response is null) + { + _alertService.SetAlertMessage(TempData, "data_not_found", false); + return RedirectToAction("Details", new { id }); + } + else + { + return View(_mapper.Map(response)); + } + } + + [HttpPost] + [Route("EditApiUser")] + [ValidateAntiForgeryToken] + public async Task EditApiUser(ApiUserViewModel apiUserDto) + { + if (ModelState.IsValid) + { + var apiUser = _mapper.Map(apiUserDto); + var response = await _httpCallService.EditData(apiUser, apiUser.ApiUserId); + if (response) + { + _alertService.SetAlertMessage(TempData, "edit_data_success", true); + return RedirectToAction("Details", new { id = apiUserDto.Id }); + } + else + { + _alertService.SetAlertMessage(TempData, "edit_data_failed", false); + return RedirectToAction("Edit", new { id = apiUserDto.Id }); + } + } + else { return RedirectToAction("Index"); } + } + + [HttpGet] + [Route("Delete/{id}")] + public async Task Delete(int id) + { + var response = await _httpCallService.DeleteData(id); + if (response) + { + _alertService.SetAlertMessage(TempData, "delete_data_success", true); + return RedirectToAction("Index"); + } + else + { + _alertService.SetAlertMessage(TempData, "delete_data_failed", false); + return RedirectToAction("Details", new { id }); + } + } + + } +} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/BaseController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/BaseController.cs new file mode 100644 index 0000000..3db947f --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Controllers/BaseController.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace AirportAutomation.Web.Controllers +{ + public class BaseController : Controller + { + public override void OnActionExecuting(ActionExecutingContext filterContext) + { + base.OnActionExecuting(filterContext); + + ViewBag.ApiUserRole = HttpContext.Session.GetString("AccessRole"); + } + } +} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/DestinationController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/DestinationController.cs index a8cef41..2b258ec 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/DestinationController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/DestinationController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class DestinationController : Controller + public class DestinationController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/FlightController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/FlightController.cs index 5ccf407..7ffd98b 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/FlightController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/FlightController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class FlightController : Controller + public class FlightController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/HealthCheckController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/HealthCheckController.cs index 9cbaac1..9b2c19d 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/HealthCheckController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/HealthCheckController.cs @@ -7,7 +7,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class HealthCheckController : Controller + public class HealthCheckController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IMapper _mapper; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/HomeController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/HomeController.cs index e132597..fd9b5c6 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/HomeController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/HomeController.cs @@ -1,11 +1,11 @@ -using AirportAutomation.Web.Authentication; -using AirportAutomation.Web.Interfaces; +using AirportAutomation.Web.Interfaces; +using AirportAutomation.Web.Models.ApiUser; using Microsoft.AspNetCore.Mvc; namespace AirportAutomation.Web.Controllers { [Route("")] - public class HomeController : Controller + public class HomeController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; @@ -26,7 +26,7 @@ public IActionResult Index(bool logout = false) string token = _httpCallService.GetToken(); if (!string.IsNullOrEmpty(token)) { - return Redirect("HealthCheck"); + return Redirect("/"); } return View("Index"); } diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/PassengerController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/PassengerController.cs index 4cf24d3..7768d10 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/PassengerController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/PassengerController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class PassengerController : Controller + public class PassengerController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/PilotController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/PilotController.cs index 514066b..f1a9a66 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/PilotController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/PilotController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class PilotController : Controller + public class PilotController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/PlaneTicketController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/PlaneTicketController.cs index f1e8066..3619d5c 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/PlaneTicketController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/PlaneTicketController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class PlaneTicketController : Controller + public class PlaneTicketController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Controllers/TravelClassController.cs b/AirportAutomation/AirportAutomationWeb/Controllers/TravelClassController.cs index 3e24e5f..632c684 100644 --- a/AirportAutomation/AirportAutomationWeb/Controllers/TravelClassController.cs +++ b/AirportAutomation/AirportAutomationWeb/Controllers/TravelClassController.cs @@ -8,7 +8,7 @@ namespace AirportAutomation.Web.Controllers { [Route("[controller]")] - public class TravelClassController : Controller + public class TravelClassController : BaseController { private readonly IHttpCallService _httpCallService; private readonly IAlertService _alertService; diff --git a/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs b/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs index 32aad44..0593e12 100644 --- a/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs +++ b/AirportAutomation/AirportAutomationWeb/Interfaces/IHttpCallService.cs @@ -1,4 +1,4 @@ -using AirportAutomation.Web.Authentication; +using AirportAutomation.Web.Models.ApiUser; using AirportAutomation.Web.Models.Response; namespace AirportAutomation.Web.Interfaces diff --git a/AirportAutomation/AirportAutomationWeb/MappingProfiles/ApiUserMappings.cs b/AirportAutomation/AirportAutomationWeb/MappingProfiles/ApiUserMappings.cs new file mode 100644 index 0000000..b1f3dc7 --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/MappingProfiles/ApiUserMappings.cs @@ -0,0 +1,18 @@ +using AirportAutomation.Core.Entities; +using AirportAutomation.Web.Models.ApiUser; +using AirportAutomation.Web.Models.Response; +using AutoMapper; + +namespace AirportAutomation.Web.MappingProfiles +{ + public class ApiUserMappings : Profile + { + public ApiUserMappings() + { + CreateMap().ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.ApiUserId)); + CreateMap().ForMember(dest => dest.ApiUserId, opt => opt.MapFrom(src => src.Id)); + + CreateMap, PagedResponse>(); + } + } +} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Models/ApiUser/ApiUserViewModel.cs b/AirportAutomation/AirportAutomationWeb/Models/ApiUser/ApiUserViewModel.cs new file mode 100644 index 0000000..a10fbe8 --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Models/ApiUser/ApiUserViewModel.cs @@ -0,0 +1,12 @@ +using System.ComponentModel; + +namespace AirportAutomation.Web.Models.ApiUser +{ + public class ApiUserViewModel + { + public int Id { get; set; } + public string UserName { get; set; } + public string Password { get; set; } + public string Roles { get; set; } + } +} diff --git a/AirportAutomation/AirportAutomationWeb/Authentication/UserViewModel.cs b/AirportAutomation/AirportAutomationWeb/Models/ApiUser/UserViewModel.cs similarity index 84% rename from AirportAutomation/AirportAutomationWeb/Authentication/UserViewModel.cs rename to AirportAutomation/AirportAutomationWeb/Models/ApiUser/UserViewModel.cs index d35313a..3594d40 100644 --- a/AirportAutomation/AirportAutomationWeb/Authentication/UserViewModel.cs +++ b/AirportAutomation/AirportAutomationWeb/Models/ApiUser/UserViewModel.cs @@ -1,7 +1,7 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace AirportAutomation.Web.Authentication +namespace AirportAutomation.Web.Models.ApiUser { public class UserViewModel { diff --git a/AirportAutomation/AirportAutomationWeb/Program.cs b/AirportAutomation/AirportAutomationWeb/Program.cs index cd42072..cc513f7 100644 --- a/AirportAutomation/AirportAutomationWeb/Program.cs +++ b/AirportAutomation/AirportAutomationWeb/Program.cs @@ -1,8 +1,11 @@ using AirportAutomation.Core.Converters; using AirportAutomation.Infrastructure.Middlewares; using AirportAutomation.Web.Binders; +using Microsoft.IdentityModel.Logging; using Serilog; +IdentityModelEventSource.ShowPII = true; + var builder = WebApplication.CreateBuilder(args); builder.Host.UseSerilog((context, loggerConfig) => diff --git a/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs b/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs index 1a432f1..c707c21 100644 --- a/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs +++ b/AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs @@ -1,6 +1,8 @@ -using AirportAutomation.Web.Authentication; -using AirportAutomation.Web.Interfaces; +using AirportAutomation.Web.Interfaces; +using AirportAutomation.Web.Models.ApiUser; using AirportAutomation.Web.Models.Response; +using Microsoft.IdentityModel.JsonWebTokens; +using System.Data; using System.Net; using System.Net.Http.Headers; using System.Web; @@ -29,7 +31,7 @@ public HttpCallService(IHttpClientFactory httpClientFactory, IHttpContextAccesso IConfiguration configuration, ILogger logger) { _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); - _httpContextAccessor = httpContextAccessor; + _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); apiURL = _configuration.GetValue("ApiSettings:apiUrl"); @@ -62,6 +64,10 @@ public async Task Authenticate(UserViewModel user) if (response.IsSuccessStatusCode) { bearerToken += await response.Content.ReadFromJsonAsync().ConfigureAwait(false); + if (!SetApiUserRole(bearerToken)) + { + return false; + } _httpContextAccessor.HttpContext.Session.SetString("AccessToken", bearerToken); return true; } @@ -71,7 +77,7 @@ public async Task Authenticate(UserViewModel user) } else { - _logger.LogError("Failed to authenticate. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to authenticate. Status code: {StatusCode}", response.StatusCode); } return false; } @@ -130,12 +136,43 @@ public bool RemoveToken() if (!string.IsNullOrEmpty(token)) { _httpContextAccessor.HttpContext.Session.Remove("AccessToken"); + _httpContextAccessor.HttpContext.Session.Remove("AccessRole"); _httpContextAccessor.HttpContext.Session.CommitAsync().Wait(); return true; } return false; } + private bool SetApiUserRole(string token) + { + var handler = new JsonWebTokenHandler(); + if (handler.CanReadToken(token)) + { + try + { + var jwtToken = handler.ReadJsonWebToken(token); + var roleClaim = jwtToken.Claims.FirstOrDefault(c => c.Type.Equals("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", StringComparison.OrdinalIgnoreCase)); + + if (roleClaim != null) + { + _httpContextAccessor.HttpContext.Session.SetString("AccessRole", roleClaim.Value); + return true; + } + else + { + _logger.LogInformation("Role claim not found in the token."); + return false; + } + } + catch (Exception ex) + { + _logger.LogInformation("Error decoding token: {Message}", ex.Message); + return false; + } + } + return false; + } + /// /// Gets a paginated list of data for a specified model type. /// @@ -172,12 +209,12 @@ public async Task> GetDataList(int page, int pageSize) } else if (response.StatusCode == HttpStatusCode.NoContent) { - _logger.LogError("Data not found. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Data not found. Status code: {StatusCode}", response.StatusCode); return new PagedResponse(Enumerable.Empty(), page, pageSize, 0); } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); return null; } } @@ -219,7 +256,7 @@ public async Task GetData(int id) } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return data; } @@ -257,7 +294,7 @@ public async Task> GetDataList() } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return null; } @@ -298,7 +335,7 @@ public async Task GetDataByName(string name) } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return null; } @@ -353,7 +390,7 @@ public async Task GetDataByFNameOrLName(string firstName, string last } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return null; } @@ -408,7 +445,7 @@ public async Task GetDataForPrice(int? minPrice, int? maxPrice) } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return null; } @@ -463,7 +500,7 @@ public async Task GetDataBetweenDates(string startDate, string endDat } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return null; } @@ -518,7 +555,7 @@ public async Task GetDataByCityOrAirport(string city, string airport) } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return null; } @@ -549,7 +586,7 @@ public async Task CreateData(T t) } else { - _logger.LogError("Failed to create data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to create data. Status code: {StatusCode}", response.StatusCode); } return data; } @@ -580,7 +617,7 @@ public async Task EditData(T t, int id) } else { - _logger.LogError("Failed to edit data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to edit data. Status code: {StatusCode}", response.StatusCode); } return false; } @@ -615,7 +652,7 @@ public async Task DeleteData(int id) } else { - _logger.LogError("Failed to delete data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to delete data. Status code: {StatusCode}", response.StatusCode); } return false; } @@ -660,7 +697,7 @@ public async Task GetHealthCheck() } else { - _logger.LogError("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); + _logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode); } return data; } diff --git a/AirportAutomation/AirportAutomationWeb/Services/TokenHelper.cs b/AirportAutomation/AirportAutomationWeb/Services/TokenHelper.cs new file mode 100644 index 0000000..15d348d --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Services/TokenHelper.cs @@ -0,0 +1,30 @@ +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; + +namespace AirportAutomation.Web.Services +{ + public static class TokenHelper + { + public static string GetUserRole(string token) + { + if (string.IsNullOrEmpty(token)) + return null; + + var handler = new JwtSecurityTokenHandler(); + if (!handler.CanReadToken(token)) + return null; + + try + { + var jwtToken = handler.ReadJwtToken(token); + var roleClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"); + return roleClaim?.Value; + } + catch (Exception ex) + { + Console.WriteLine($"Error decoding token: {ex.Message}"); + return null; + } + } + } +} diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml index f40b0aa..166d3f7 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Create.cshtml @@ -9,33 +9,38 @@ @Html.AntiForgeryToken() -

Create Airline

-
-
-
-
-
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Create Airline

+
+
+
+
+
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml index 65c25aa..cbd8042 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Details.cshtml @@ -31,6 +31,9 @@ { @await Html.PartialAsync("_AlertPartial", TempData) } -
- @await Html.PartialAsync("_EditButtons", Model) -
\ No newline at end of file +@if (ViewBag.ApiUserRole != "User") +{ +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml index 353cb4b..8dbca7c 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Edit.cshtml @@ -6,37 +6,42 @@ @Html.AntiForgeryToken() -

Edit Airline

-
-
-
-
-
-
- - - -
-
- - - -
-
- -
-
-
-
-@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") - -@section Scripts { +

Edit Airline

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Airline/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Airline/Index.cshtml index 4162331..703ba41 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Airline/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Airline/Index.cshtml @@ -7,11 +7,14 @@
-
-
- Create Airline + @if (ViewBag.ApiUserRole != "User") + { + -
+ } @if (Model != null) {
diff --git a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml new file mode 100644 index 0000000..b0724f8 --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Details.cshtml @@ -0,0 +1,55 @@ +@model AirportAutomation.Web.Models.ApiUser.ApiUserViewModel; + +@{ + ViewData["Title"] = "View"; +} +@{ + ViewBag.Title = "Api User Details"; +} + +@Html.AntiForgeryToken() + +@if (ViewBag.ApiUserRole == "SuperAdmin") +{ +
+

Airline Details

+
+
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+ @Html.DisplayNameFor(model => model.UserName) +
+
+ @Html.DisplayFor(model => model.UserName) +
+
+ @Html.DisplayNameFor(model => model.Password) +
+
+ @Html.DisplayFor(model => model.Password) +
+
+ @Html.DisplayNameFor(model => model.Roles) +
+
+ @Html.DisplayFor(model => model.Roles) +
+
+
+ @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml new file mode 100644 index 0000000..2ec2108 --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Edit.cshtml @@ -0,0 +1,59 @@ +@model AirportAutomation.Web.Models.ApiUser.ApiUserViewModel; + +@{ + ViewData["Title"] = "Edit"; +} + +@Html.AntiForgeryToken() +@if (ViewBag.ApiUserRole == "SuperAdmin") +{ +

Edit Api User

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+} +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} + +@if (TempData["AlertMessage"] != null) +{ + @await Html.PartialAsync("_AlertPartial", TempData) +} + +@await Html.PartialAsync("_BackToListPartial") + +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } +} diff --git a/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml new file mode 100644 index 0000000..44616b0 --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Views/ApiUser/Index.cshtml @@ -0,0 +1,97 @@ +@model PagedResponse + +@{ + ViewBag.Title = "Api Users"; +} + +@if (ViewBag.ApiUserRole == "SuperAdmin") +{ +
+
+
+ @if (Model != null) + { +
+ + + +
+ } +
+
+
+
+
+ @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } +
+ +
+
+ @if (Model != null) + { +
+ + + + + + + + + + + @foreach (var item in Model.Data) + { + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Data.First().Id) + + @Html.DisplayNameFor(model => model.Data.First().UserName) + + @Html.DisplayNameFor(model => model.Data.First().Password) + + @Html.DisplayNameFor(model => model.Data.First().Roles) +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.UserName) + + @Html.DisplayFor(modelItem => item.Password) + + @Html.DisplayFor(modelItem => item.Roles) +
+ @await Html.PartialAsync("_Pagination", Model) + } + else + { + @await Html.PartialAsync("_DataNotFound") + } +
+
+} +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} + +@section Scripts { + + + +} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml index 2e1dd40..a968475 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Create.cshtml @@ -9,38 +9,43 @@ @Html.AntiForgeryToken() -

Create Destination

-
-
-
-
-
-
- - - -
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Create Destination

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml index ed65d79..7c052ba 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Details.cshtml @@ -37,9 +37,12 @@ { @await Html.PartialAsync("_AlertPartial", TempData) } -
- @await Html.PartialAsync("_EditButtons", Model) -
+@if (ViewBag.ApiUserRole != "User") +{ +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} @section Scripts { } diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml index b577ab7..358c0f2 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Edit.cshtml @@ -6,43 +6,48 @@ @Html.AntiForgeryToken() -

Edit Destination

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Edit Destination

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Destination/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Destination/Index.cshtml index 5ea1add..34f20b2 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Destination/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Destination/Index.cshtml @@ -7,11 +7,14 @@
-
-
- Create Destination + @if (ViewBag.ApiUserRole != "User") + { + -
+ } @if (Model != null) {
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml index de2d9b7..ec4a8bc 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Create.cshtml @@ -9,66 +9,71 @@ @Html.AntiForgeryToken() -

Create Flight

-
-
-
-
-
-
- - - -
-
- - - -
-
- -
-
- -
-
-
-
- - - +@if (ViewBag.ApiUserRole != "User") +{ +

Create Flight

+
+ +
+
+
+
+ + + +
+
+ + + +
+
+ +
+
+ +
-
- - - +
+
+ + + +
+
+ + + +
-
-
-
-
+
+
+
+
+ + +
- - -
-
- - -@if (TempData["AlertMessage"] != null) -{ - @await Html.PartialAsync("_AlertPartial", TempData) -} + -@await Html.PartialAsync("_BackToListPartial") - -@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } + } - -} \ No newline at end of file +} +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml index 199d4c3..549336e 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Details.cshtml @@ -134,6 +134,9 @@ { @await Html.PartialAsync("_AlertPartial", TempData) } -
- @await Html.PartialAsync("_EditButtons", Model) -
\ No newline at end of file +@if (ViewBag.ApiUserRole != "User") +{ +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml index 7396acb..6d152c1 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Edit.cshtml @@ -6,60 +6,65 @@ @Html.AntiForgeryToken() -

Edit Flight

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- - - -
-
- - - +@if (ViewBag.ApiUserRole != "User") +{ +

Edit Flight

+
+ +
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
-
- - - +
+
+ + + +
+
+ + + +
+
+ + + +
-
- - -@if (TempData["AlertMessage"] != null) -{ - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") + -@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") diff --git a/AirportAutomation/AirportAutomationWeb/Views/Flight/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Flight/Index.cshtml index 7d7da84..bbd0074 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Flight/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Flight/Index.cshtml @@ -7,9 +7,12 @@
- + @if (ViewBag.ApiUserRole != "User") + { + + } @if (Model != null) {
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Home/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Home/Index.cshtml index a3a0309..f6e7258 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Home/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Home/Index.cshtml @@ -1,4 +1,4 @@ -@model AirportAutomation.Web.Authentication.UserViewModel +@model AirportAutomation.Web.Models.ApiUser.UserViewModel; @{ ViewBag.Title = "Home"; diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml index 0564d3c..49f0de7 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Create.cshtml @@ -9,58 +9,63 @@ @Html.AntiForgeryToken() -

Create Passenger

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Create Passenger

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml index 930366e..3161e90 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Details.cshtml @@ -60,9 +60,12 @@ { @await Html.PartialAsync("_AlertPartial", TempData) } -
- @await Html.PartialAsync("_EditButtons", Model) -
+@if (ViewBag.ApiUserRole != "User") +{ +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} @section Scripts { } \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml index 647b566..584aa95 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Edit.cshtml @@ -6,63 +6,68 @@ @Html.AntiForgeryToken() -

Edit Passenger

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Edit Passenger

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Index.cshtml index 3511dbc..bde51e9 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Passenger/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Passenger/Index.cshtml @@ -7,9 +7,12 @@
- + @if (ViewBag.ApiUserRole != "User") + { + + } @if (Model != null) {
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml index 50681ee..e4417a7 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Create.cshtml @@ -9,48 +9,53 @@ @Html.AntiForgeryToken() -

Create Pilot

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Create Pilot

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml index 45c44cd..6e560cd 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Details.cshtml @@ -48,6 +48,9 @@ { @await Html.PartialAsync("_AlertPartial", TempData) } -
- @await Html.PartialAsync("_EditButtons", Model) -
+@if (ViewBag.ApiUserRole != "User") +{ +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml index 1356d6d..01e407e 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Edit.cshtml @@ -6,53 +6,58 @@ @Html.AntiForgeryToken() -

Edit Pilot

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- -@if (TempData["AlertMessage"] != null) +@if (ViewBag.ApiUserRole != "User") { - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") +

Edit Pilot

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
-@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml index e60bed7..8718086 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Pilot/Index.cshtml @@ -2,102 +2,106 @@ @{ - ViewBag.Title = "Pilots"; + ViewBag.Title = "Pilots"; }
-
-
- - @if (Model != null) - { -
- - +
+
+ @if (ViewBag.ApiUserRole != "User") + { + + } + @if (Model != null) + { +
+ + - - + + - -
- } -
-
+ +
+ } +
+

- @if (TempData["AlertMessage"] != null) - { - @await Html.PartialAsync("_AlertPartial", TempData) - } + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + }
-
- @if (Model != null) - { -
- - - - - - - - - - - - @foreach (var item in Model.Data) - { - - - - - - - - } - -
- @Html.DisplayNameFor(model => model.Data.First().Id) - - @Html.DisplayNameFor(model => model.Data.First().FirstName) - - @Html.DisplayNameFor(model => model.Data.First().LastName) - - @Html.DisplayNameFor(model => model.Data.First().UPRN) - - @Html.DisplayNameFor(model => model.Data.First().FlyingHours) -
- @Html.DisplayFor(modelItem => item.Id) - - @Html.DisplayFor(modelItem => item.FirstName) - - @Html.DisplayFor(modelItem => item.LastName) - - @Html.DisplayFor(modelItem => item.UPRN) - - @Html.DisplayFor(modelItem => item.FlyingHours) -
- @await Html.PartialAsync("_Pagination", Model) - } - else { - @await Html.PartialAsync("_DataNotFound") - } -
+
+ @if (Model != null) + { +
+ + + + + + + + + + + + @foreach (var item in Model.Data) + { + + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Data.First().Id) + + @Html.DisplayNameFor(model => model.Data.First().FirstName) + + @Html.DisplayNameFor(model => model.Data.First().LastName) + + @Html.DisplayNameFor(model => model.Data.First().UPRN) + + @Html.DisplayNameFor(model => model.Data.First().FlyingHours) +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.FirstName) + + @Html.DisplayFor(modelItem => item.LastName) + + @Html.DisplayFor(modelItem => item.UPRN) + + @Html.DisplayFor(modelItem => item.FlyingHours) +
+ @await Html.PartialAsync("_Pagination", Model) + } + else + { + @await Html.PartialAsync("_DataNotFound") + } +
@section Scripts { - - - + + + } \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml index 595a943..b7028f0 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Create.cshtml @@ -9,69 +9,74 @@ @Html.AntiForgeryToken() -

Create Plane Ticket

-
-
-
-
-
-
- - - -
-
- - - -
-
- -
+@if (ViewBag.ApiUserRole != "User") +{ +

Create Plane Ticket

+
+ +
+
- +
+ + + +
+
+ + + +
+
+ +
+
+ +
-
-
-
- - - -
-
- - - -
-
-
-
- - - +
+
+ + + +
+
+ + + +
-
- - - +
+
+ + + +
+
+ + + +
-
- - -@if (TempData["AlertMessage"] != null) -{ - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") + -@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } + } - -} \ No newline at end of file +} +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml index a067c01..29cac1e 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Details.cshtml @@ -128,6 +128,9 @@ { @await Html.PartialAsync("_AlertPartial", TempData) } -
- @await Html.PartialAsync("_EditButtons", Model) -
\ No newline at end of file +@if (ViewBag.ApiUserRole != "User") +{ +
+ @await Html.PartialAsync("_EditButtons", Model) +
+} \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml index ff3e266..c25232c 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Edit.cshtml @@ -6,66 +6,71 @@ @Html.AntiForgeryToken() -

Edit Plane Ticket

-
-
-
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
+@if (ViewBag.ApiUserRole != "User") +{ +

Edit Plane Ticket

+
+ +
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
-
- -
-
-
-
- - - -
-
- - - +
+ +
-
- - - +
+
+ + + +
+
+ + + +
+
+ + + +
-
- + -@if (TempData["AlertMessage"] != null) -{ - @await Html.PartialAsync("_AlertPartial", TempData) -} - -@await Html.PartialAsync("_BackToListPartial") - -@section Scripts { + @if (TempData["AlertMessage"] != null) + { + @await Html.PartialAsync("_AlertPartial", TempData) + } + @section Scripts { @{ - await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } } } +else +{ + @await Html.PartialAsync("_ForbiddenAccess") +} +@await Html.PartialAsync("_BackToListPartial") \ No newline at end of file diff --git a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Index.cshtml b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Index.cshtml index d6cf13c..cdf7eb4 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Index.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/PlaneTicket/Index.cshtml @@ -7,9 +7,12 @@
- + @if (ViewBag.ApiUserRole != "User") + { + + } @if (Model != null) {
diff --git a/AirportAutomation/AirportAutomationWeb/Views/Shared/_ForbiddenAccess.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Shared/_ForbiddenAccess.cshtml new file mode 100644 index 0000000..22016ca --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Views/Shared/_ForbiddenAccess.cshtml @@ -0,0 +1,6 @@ +
+
+
+ diff --git a/AirportAutomation/AirportAutomationWeb/Views/Shared/_ForbiddenAccess.cshtml.css b/AirportAutomation/AirportAutomationWeb/Views/Shared/_ForbiddenAccess.cshtml.css new file mode 100644 index 0000000..a72cbea --- /dev/null +++ b/AirportAutomation/AirportAutomationWeb/Views/Shared/_ForbiddenAccess.cshtml.css @@ -0,0 +1,48 @@ +/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification +for details on configuring this project to bundle and minify static web assets. */ + +a.navbar-brand { + white-space: normal; + text-align: center; + word-break: break-all; +} + +a { + color: #0077cc; +} + +.btn-primary { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.nav-pills .nav-link.active, .nav-pills .show > .nav-link { + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; +} + +.border-top { + border-top: 1px solid #e5e5e5; +} +.border-bottom { + border-bottom: 1px solid #e5e5e5; +} + +.box-shadow { + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); +} + +button.accept-policy { + font-size: 1rem; + line-height: inherit; +} + +.footer { + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; +} diff --git a/AirportAutomation/AirportAutomationWeb/Views/Shared/_Layout.cshtml b/AirportAutomation/AirportAutomationWeb/Views/Shared/_Layout.cshtml index e86ee63..c156461 100644 --- a/AirportAutomation/AirportAutomationWeb/Views/Shared/_Layout.cshtml +++ b/AirportAutomation/AirportAutomationWeb/Views/Shared/_Layout.cshtml @@ -17,7 +17,6 @@ -
@@ -51,6 +50,9 @@ +