-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,372 additions
and
754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
AirportAutomation/AirportAutomationWeb/Controllers/ApiUserController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IActionResult> 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<ApiUserEntity>(page, pageSize); | ||
if (response == null) | ||
{ | ||
return View(); | ||
} | ||
var pagedResponse = _mapper.Map<PagedResponse<ApiUserViewModel>>(response); | ||
return View(pagedResponse); | ||
} | ||
|
||
[HttpGet] | ||
[Route("{id}")] | ||
public async Task<IActionResult> Details(int id) | ||
{ | ||
var response = await _httpCallService.GetData<ApiUserEntity>(id); | ||
if (response is null) | ||
{ | ||
_alertService.SetAlertMessage(TempData, "data_not_found", false); | ||
return RedirectToAction("Index"); | ||
} | ||
else | ||
{ | ||
return View(_mapper.Map<ApiUserViewModel>(response)); | ||
} | ||
} | ||
|
||
|
||
[HttpGet] | ||
[Route("GetApiUsersByName/{name}")] | ||
public async Task<IActionResult> GetApiUsersByName(string name) | ||
{ | ||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
_alertService.SetAlertMessage(TempData, "missing_field", false); | ||
return RedirectToAction("Index"); | ||
} | ||
var response = await _httpCallService.GetDataByName<ApiUserEntity>(name); | ||
return Json(response); | ||
} | ||
|
||
[HttpGet] | ||
[Route("Create")] | ||
public IActionResult Create() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("Edit/{id}")] | ||
public async Task<IActionResult> Edit(int id) | ||
{ | ||
var response = await _httpCallService.GetData<ApiUserEntity>(id); | ||
if (response is null) | ||
{ | ||
_alertService.SetAlertMessage(TempData, "data_not_found", false); | ||
return RedirectToAction("Details", new { id }); | ||
} | ||
else | ||
{ | ||
return View(_mapper.Map<ApiUserViewModel>(response)); | ||
} | ||
} | ||
|
||
[HttpPost] | ||
[Route("EditApiUser")] | ||
[ValidateAntiForgeryToken] | ||
public async Task<IActionResult> EditApiUser(ApiUserViewModel apiUserDto) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var apiUser = _mapper.Map<ApiUserEntity>(apiUserDto); | ||
var response = await _httpCallService.EditData<ApiUserEntity>(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<IActionResult> Delete(int id) | ||
{ | ||
var response = await _httpCallService.DeleteData<ApiUserEntity>(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 }); | ||
} | ||
} | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
AirportAutomation/AirportAutomationWeb/Controllers/BaseController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.