Browse Source

1.修改SYS模组,全部采用新ResultModel

2.同时修改其他模组有关联到SYS的部分
3.修正KCSController提示此异步方法缺少 "await" 运算符,将以同步方式运行。
PTD
Marvin 3 years ago
parent
commit
53fc01454c
  1. 4
      AMESCoreStudio.Web/Controllers/BASController.cs
  2. 35
      AMESCoreStudio.Web/Controllers/HomeController.cs
  3. 4
      AMESCoreStudio.Web/Controllers/JIGController.cs
  4. 14
      AMESCoreStudio.Web/Controllers/KCSController.cs
  5. 16
      AMESCoreStudio.Web/Controllers/PPSController.cs
  6. 4
      AMESCoreStudio.Web/Controllers/SPCController.cs
  7. 109
      AMESCoreStudio.Web/Controllers/SYSController.cs
  8. 26
      AMESCoreStudio.Web/HttpApis/ISYS.cs
  9. 39
      AMESCoreStudio.WebApi/Controllers/SYS/DeptInfoesController.cs
  10. 60
      AMESCoreStudio.WebApi/Controllers/SYS/ProgramInfoesController.cs
  11. 59
      AMESCoreStudio.WebApi/Controllers/SYS/RoleInfoesController.cs
  12. 56
      AMESCoreStudio.WebApi/Controllers/SYS/RoleModulesController.cs
  13. 54
      AMESCoreStudio.WebApi/Controllers/SYS/RoleProgramsController.cs
  14. 60
      AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs
  15. 55
      AMESCoreStudio.WebApi/Controllers/SYS/UserRolesController.cs

4
AMESCoreStudio.Web/Controllers/BASController.cs

@ -102,9 +102,9 @@ namespace AMESCoreStudio.Web.Controllers
var result = await _sysApi.GetUserInfoes();
var UserItems = new List<SelectListItem>();
for (int i = 0; i < result.Count; i++)
foreach (var item in result.Data)
{
UserItems.Add(new SelectListItem("[" + result[i].UserNo + "]" + result[i].UserName, result[i].UserID.ToString()));
UserItems.Add(new SelectListItem("[" + item.UserNo + "]" + item.UserName, item.UserID.ToString()));
}
ViewBag.UserList = UserItems;
}

35
AMESCoreStudio.Web/Controllers/HomeController.cs

@ -47,17 +47,19 @@ namespace AMESCoreStudio.Web.Controllers
{
int user_id = int.Parse(userID.ToString());
var userRole = await _sysApi.GetUserRolesByUser(user_id);
int role_id = userRole[0].RoleID;
int role_id = userRole.Data.ToList()[0].RoleID;
var userModule = await _sysApi.GetRoleModulesByRole(role_id, 0, 10);
var userProgram = await _sysApi.GetRoleProgramsByRole(role_id, 0, 10);
string menuData = "<ul id = 'nav' class='layui-tab-item layui-show'>";
for (int i = 0; i < userModule.Count; i++)
int i = 0;
foreach (var user_module in userModule.Data)
{
int module_id = userModule[i].ModuleID;
int module_id = user_module.ModuleID;
i = i + 1;
if (i == 0)
{
menuData = menuData + "<li class='open'>";
@ -67,17 +69,24 @@ namespace AMESCoreStudio.Web.Controllers
menuData = menuData + "<li>";
}
menuData = menuData + "<a class='border active'>";
menuData = menuData + "<i class='fa fa-star fa-fw' style='color:#77B272;'></i><cite style='color:#77B272;'> " + userModule[i].Module.ModuleName + " </cite><i class='fa fa-angle-up fa-fw nav_right'></i>";
menuData = menuData + "</a>";
menuData = menuData + "<ul class='sub-menu' style='display: block;'>";
for (int j = 0; j < userProgram.Count; j++)
if (user_module.Module != null)
{
menuData = menuData + "<a class='border active'>";
menuData = menuData + "<i class='fa fa-star fa-fw' style='color:#77B272;'></i><cite style='color:#77B272;'> " + user_module.Module.ModuleName + " </cite><i class='fa fa-angle-up fa-fw nav_right'></i>";
menuData = menuData + "</a>";
menuData = menuData + "<ul class='sub-menu' style='display: block;'>";
}
foreach (var user_program in userProgram.Data)
{
if (userProgram[j].Program.ModuleID == module_id)
if (user_program.Program != null)
{
menuData = menuData + "<li class='sub-tab' hg-title='" + userProgram[j].Program.ProgramName + "' hg-nav='" + userProgram[j].Program.ProgramPath + "'>";
menuData = menuData + "<a><i class='fa fa-key fa-fw'></i><cite>" + userProgram[j].Program.ProgramName + "</cite></a>";
menuData = menuData + "</li>";
if (user_program.Program.ModuleID == module_id)
{
menuData = menuData + "<li class='sub-tab' hg-title='" + user_program.Program.ProgramName + "' hg-nav='" + user_program.Program.ProgramPath + "'>";
menuData = menuData + "<a><i class='fa fa-key fa-fw'></i><cite>" + user_program.Program.ProgramName + "</cite></a>";
menuData = menuData + "</li>";
}
}
}
menuData = menuData + "</ul>";

4
AMESCoreStudio.Web/Controllers/JIGController.cs

@ -131,9 +131,9 @@ namespace AMESCoreStudio.Web.Controllers
var result = await _sysApi.GetUserInfoes();
var UserItems = new List<SelectListItem>();
for (int i = 0; i < result.Count; i++)
foreach (var item in result.Data)
{
UserItems.Add(new SelectListItem(result[i].UserName, result[i].UserID.ToString()));
UserItems.Add(new SelectListItem(item.UserName, item.UserID.ToString()));
}
ViewBag.UserList = UserItems;
}

14
AMESCoreStudio.Web/Controllers/KCSController.cs

@ -45,7 +45,7 @@ namespace AMESCoreStudio.Web.Controllers
}
private async Task GetItemType()
private void GetItemType()
{
var ItemTypeList = new List<SelectListItem>();
@ -66,7 +66,7 @@ namespace AMESCoreStudio.Web.Controllers
ViewBag.ItemTypeList = ItemTypeList;
}
private async Task GetSNInterval()
private void GetSNInterval()
{
var SNIntervalList = new List<SelectListItem>();
@ -446,10 +446,10 @@ namespace AMESCoreStudio.Web.Controllers
}
//新增頁面
public async Task<IActionResult> KCS006C()
public IActionResult KCS006C()
{
await GetItemType();
await GetSNInterval();
GetItemType();
GetSNInterval();
return View();
}
@ -458,8 +458,8 @@ namespace AMESCoreStudio.Web.Controllers
[HttpGet]
public async Task<IActionResult> KCS006UAsync(string id)
{
await GetItemType();
await GetSNInterval();
GetItemType();
GetSNInterval();
var result = await _kcsApi.GetItems(id);

16
AMESCoreStudio.Web/Controllers/PPSController.cs

@ -212,7 +212,7 @@ namespace AMESCoreStudio.Web.Controllers
return Json(new { data = item });
}
private async Task GetStatusList()
private void GetStatusList()
{
var StatusList = new List<SelectListItem>();
@ -1311,9 +1311,9 @@ namespace AMESCoreStudio.Web.Controllers
}
//新增頁面
public async Task<IActionResult> PPS011C()
public IActionResult PPS011C()
{
await GetStatusList();
GetStatusList();
return View();
}
@ -1321,7 +1321,7 @@ namespace AMESCoreStudio.Web.Controllers
[HttpGet]
public async Task<IActionResult> PPS011UAsync(string id)
{
await GetStatusList();
GetStatusList();
var result = await _ppsApi.GetRMAGroup(id);
@ -1425,7 +1425,7 @@ namespace AMESCoreStudio.Web.Controllers
//新增頁面
public async Task<IActionResult> PPS012C(string id)
{
await GetStatusList();
GetStatusList();
await GetRMAGroupList();
var model = new RMAClass();
@ -1444,7 +1444,7 @@ namespace AMESCoreStudio.Web.Controllers
[HttpGet]
public async Task<IActionResult> PPS012UAsync(string id)
{
await GetStatusList();
GetStatusList();
await GetRMAGroupList();
var result = await _ppsApi.GetRMAClass(id);
@ -1560,7 +1560,7 @@ namespace AMESCoreStudio.Web.Controllers
await GetRMAClassList(param[1]);
await GetResponseDeptList();
await GetStatusList();
GetStatusList();
await GetQATypeList();
var model = new RMAReason();
@ -1582,7 +1582,7 @@ namespace AMESCoreStudio.Web.Controllers
string[] param = id.Split(',');
await GetRMAClassList(param[1]);
await GetResponseDeptList();
await GetStatusList();
GetStatusList();
await GetQATypeList();
var result = await _ppsApi.GetRMAReason(param[0]);

4
AMESCoreStudio.Web/Controllers/SPCController.cs

@ -234,9 +234,9 @@ namespace AMESCoreStudio.Web.Controllers
var UserItems = new List<SelectListItem>();
UserItems.Add(new SelectListItem("N/A", "-1"));
for (int i = 0; i < result.Count; i++)
foreach (var item in result.Data)
{
UserItems.Add(new SelectListItem(result[i].UserName, result[i].UserID.ToString()));
UserItems.Add(new SelectListItem(item.UserName, item.UserID.ToString()));
}
ViewBag.UserList = UserItems;
}

109
AMESCoreStudio.Web/Controllers/SYSController.cs

@ -87,9 +87,9 @@ namespace AMESCoreStudio.Web.Controllers
var result = await _sysApi.GetRoleInfoes();
var RoleItems = new List<SelectListItem>();
for (int i = 0; i < result.Count; i++)
foreach (var item in result.Data)
{
RoleItems.Add(new SelectListItem(result[i].RoleName, result[i].RoleID.ToString()));
RoleItems.Add(new SelectListItem(item.RoleName, item.RoleID.ToString()));
}
ViewBag.RoleList = RoleItems;
}
@ -111,9 +111,9 @@ namespace AMESCoreStudio.Web.Controllers
var result = await _sysApi.GetUserInfoes();
var UserItems = new List<SelectListItem>();
for (int i = 0; i < result.Count; i++)
foreach (var item in result.Data)
{
UserItems.Add(new SelectListItem(result[i].UserNo + result[i].UserName, result[i].UserID.ToString()));
UserItems.Add(new SelectListItem(item.UserNo + item.UserName, item.UserID.ToString()));
}
ViewBag.UserList = UserItems;
}
@ -340,6 +340,27 @@ namespace AMESCoreStudio.Web.Controllers
[HttpGet]
public async Task<IActionResult> GetModuleInfoesBySystemAsync(int systemID, int page = 0, int limit = 10)
{
var system_id = "";
HttpContext.Request.Cookies.TryGetValue("SystemID4SYS002", out system_id);
if (system_id != null)
{
if (systemID == 0)
{
systemID = int.Parse(system_id.ToString());
}
else
{
HttpContext.Response.Cookies.Append("SystemID4SYS002", systemID.ToString());
}
}
else
{
if (systemID > 0)
{
HttpContext.Response.Cookies.Append("SystemID4SYS002", systemID.ToString());
}
}
var result = await _sysApi.GetModuleInfoesBySystem(systemID, page, limit);
@ -419,14 +440,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutProgramInfo(model.ProgramID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.ProgramID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors != null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -461,13 +482,32 @@ namespace AMESCoreStudio.Web.Controllers
[HttpGet]
public async Task<IActionResult> GetProgramInfoesByModuleAsync(int moduleID, int page = 0, int limit = 10)
{
var result = await _sysApi.GetProgramInfoesByMoudle(moduleID, page, limit);
var result_total = await _sysApi.GetProgramInfoesByMoudle(moduleID, 0, limit);
var module_id = "";
HttpContext.Request.Cookies.TryGetValue("ModuleID4SYS003", out module_id);
if (module_id != null)
{
if (moduleID == 0)
{
moduleID = int.Parse(module_id.ToString());
}
else
{
HttpContext.Response.Cookies.Append("ModuleID4SYS003", moduleID.ToString());
}
}
else
{
if (moduleID > 0)
{
HttpContext.Response.Cookies.Append("ModuleID4SYS003", moduleID.ToString());
}
}
var result = await _sysApi.GetProgramInfoesByMoudle(moduleID, page, limit);
if (result.Count > 0)
if (result.DataTotal > 0)
{
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count });
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
}
return Json(new Table() { count = 0, data = null });
@ -523,14 +563,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutRoleInfo(model.RoleID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.RoleID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors != null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -552,11 +592,10 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetRoleInfoesAsync(int page = 0, int limit = 10)
{
var result = await _sysApi.GetRoleInfoes(page,limit);
var result_total = await _sysApi.GetRoleInfoes(0,limit);
if (result.Count > 0)
if (result.DataTotal > 0)
{
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count });
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
}
return Json(new Table() { count = 0, data = null });
@ -646,14 +685,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutRoleModule(model.RoleModuleID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.RoleModuleID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors!=null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -689,11 +728,10 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetRoleModulesByRoleAsync(int roleID, int page = 0, int limit = 10)
{
var result = await _sysApi.GetRoleModulesByRole(roleID,page,limit);
var result_total = await _sysApi.GetRoleModulesByRole(roleID, 0, limit);
if (result.Count > 0)
if (result.DataTotal > 0)
{
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count });
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
}
return Json(new Table() { count = 0, data = null });
@ -783,14 +821,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutRoleProgram(model.RoleProgramID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.RoleProgramID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors != null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -826,11 +864,10 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetRoleProgramsByRoleAsync(int roleID, int page = 0, int limit = 10)
{
var result = await _sysApi.GetRoleProgramsByRole(roleID, page, limit);
var result_total = await _sysApi.GetRoleProgramsByRole(roleID,0,limit);
if (result.Count > 0)
if (result.DataTotal > 0)
{
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count });
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
}
return Json(new Table() { count = 0, data = null });
@ -898,14 +935,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutDeptInfo(model.DeptID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.DeptID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors!=null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -1006,14 +1043,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutUserInfo(model.UserID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.UserID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors!=null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -1036,11 +1073,10 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetUserInfoesAsync(int page = 0, int limit = 10)
{
var result = await _sysApi.GetUserInfoes(page,limit);
var result_total = await _sysApi.GetUserInfoes(0,limit);
if (result.Count > 0)
if (result.DataTotal > 0)
{
return Json(new Table() { code = 0, msg = "", data = result, count = result_total.Count });
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
}
return Json(new Table() { count = 0, data = null });
@ -1129,14 +1165,14 @@ namespace AMESCoreStudio.Web.Controllers
result = await _sysApi.PutUserRole(model.UserRoleID, JsonConvert.SerializeObject(model));
}
if (!result.Success)
if (result.Success)
{
var _msg = model.UserRoleID == 0 ? "添加成功!" : "修改成功!";
return RedirectToAction("Refresh", "Home", new { msg = _msg });
}
else
{
if (result.Errors.Count > 0)
if (result.Errors!=null)
{
ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg);
}
@ -1172,11 +1208,10 @@ namespace AMESCoreStudio.Web.Controllers
public async Task<IActionResult> GetUserRolesByUserAsync(int userID, int page = 0, int limit = 10)
{
var result = await _sysApi.GetUserRolesByUser(userID,page,limit);
var result_total = await _sysApi.GetUserRolesByUser(userID,0,limit);
if (result.Count > 0)
if (result.DataTotal > 0)
{
return Json(new Table() { code = 0, msg = "", data = result, count = result.Count });
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
}
return Json(new Table() { count = 0, data = null });

26
AMESCoreStudio.Web/HttpApis/ISYS.cs

@ -117,7 +117,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/ProgramInfoes/{id}")]
ITask<ResultModel<string>> DeleteProgramInfo(int id);
ITask<ResultModel<ProgramInfo>> DeleteProgramInfo(int id);
/// <summary>
/// 根據ID獲取指定功能資料
@ -138,7 +138,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/ProgramInfoes/Module/{id}")]
ITask<List<ProgramInfo>> GetProgramInfoesByMoudle(int id, int page = 0, int limit = 10);
ITask<ResultModel<ProgramInfo>> GetProgramInfoesByMoudle(int id, int page = 0, int limit = 10);
#endregion
@ -163,7 +163,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/RoleInfoes/{id}")]
ITask<ResultModel<string>> DeleteRoleInfo(int id);
ITask<ResultModel<RoleInfo>> DeleteRoleInfo(int id);
/// <summary>
/// 根據ID獲取指定角色資料
@ -177,7 +177,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/RoleInfoes")]
ITask<List<RoleInfo>> GetRoleInfoes(int page = 0, int limit = 10);
ITask<ResultModel<RoleInfo>> GetRoleInfoes(int page = 0, int limit = 10);
#endregion
@ -202,7 +202,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/RoleModules/{id}")]
ITask<ResultModel<string>> DeleteRoleModule(int id);
ITask<ResultModel<RoleModule>> DeleteRoleModule(int id);
/// <summary>
/// 根據ID獲取指定角色模组資料
@ -223,7 +223,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/RoleModules/Role/{id}")]
ITask<List<RoleModule>> GetRoleModulesByRole(int id, int page = 0, int limit = 10);
ITask<ResultModel<RoleModule>> GetRoleModulesByRole(int id, int page = 0, int limit = 10);
#endregion
@ -248,7 +248,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/RolePrograms/{id}")]
ITask<ResultModel<string>> DeleteRoleProgram(int id);
ITask<ResultModel<RoleProgram>> DeleteRoleProgram(int id);
/// <summary>
/// 根據ID獲取指定角色功能資料
@ -269,7 +269,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/RolePrograms/Role/{id}")]
ITask<List<RoleProgram>> GetRoleProgramsByRole(int id, int page = 0, int limit = 10);
ITask<ResultModel<RoleProgram>> GetRoleProgramsByRole(int id, int page = 0, int limit = 10);
#endregion
@ -294,7 +294,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/DeptInfoes/{id}")]
ITask<ResultModel<string>> DeleteDeptInfo(int id);
ITask<ResultModel<DeptInfo>> DeleteDeptInfo(int id);
/// <summary>
/// 根據ID獲取指定部门資料
@ -333,7 +333,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/UserInfoes/{id}")]
ITask<ResultModel<string>> DeleteUserInfo(int id);
ITask<ResultModel<UserInfo>> DeleteUserInfo(int id);
/// <summary>
/// 根據ID獲取指定用户資料
@ -347,7 +347,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/UserInfoes")]
ITask<List<UserInfo>> GetUserInfoes(int page = 0, int limit = 10);
ITask<ResultModel<UserInfo>> GetUserInfoes(int page = 0, int limit = 10);
/// <summary>
/// 用UserNo 查詢
@ -380,7 +380,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpDelete("api/UserRoles/{id}")]
ITask<ResultModel<string>> DeleteUserRole(int id);
ITask<ResultModel<UserRole>> DeleteUserRole(int id);
/// <summary>
/// 根據ID獲取指定用户角色資料
@ -401,7 +401,7 @@ namespace AMESCoreStudio.Web
/// </summary>
/// <returns></returns>
[WebApiClient.Attributes.HttpGet("api/UserRoles/User/{id}")]
ITask<List<UserRole>> GetUserRolesByUser(int id, int page = 0, int limit = 10);
ITask<ResultModel<UserRole>> GetUserRolesByUser(int id, int page = 0, int limit = 10);
#endregion

39
AMESCoreStudio.WebApi/Controllers/SYS/DeptInfoesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -78,11 +79,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<DeptInfo>> PutDeptInfo(int id, [FromBody] DeptInfo deptInfo)
public async Task<ResultModel<DeptInfo>> PutDeptInfo(int id, [FromBody] DeptInfo deptInfo)
{
ResultModel<DeptInfo> result = new ResultModel<DeptInfo>();
if (id != deptInfo.DeptID)
{
return BadRequest();
result.Msg = "部門編號錯誤";
result.Success = false;
return result;
}
_context.Entry(deptInfo).State = EntityState.Modified;
@ -96,7 +101,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!DeptInfoExists(id))
{
return NotFound();
result.Msg = "部門編號不存在";
result.Success = false;
return result;
}
else
{
@ -104,8 +111,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return deptInfo;
//return NoContent();
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -117,8 +125,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<DeptInfo>> PostDeptInfo([FromBody] DeptInfo deptInfo)
public async Task<ResultModel<DeptInfo>> PostDeptInfo([FromBody] DeptInfo deptInfo)
{
ResultModel<DeptInfo> result = new ResultModel<DeptInfo>();
Helper helper = new Helper(_context);
deptInfo.DeptID = helper.GetIDKey("DEPT_ID").Result;
@ -128,7 +138,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.DeptInfoes.Add(deptInfo);
await _context.SaveChangesAsync();
return CreatedAtAction("GetDeptInfo", new { id = deptInfo.DeptID }, deptInfo);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -138,20 +150,25 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/DeptInfoes/5
[HttpDelete("{id}")]
public async Task<ActionResult<DeptInfo>> DeleteDeptInfo(int id)
public async Task<ResultModel<DeptInfo>> DeleteDeptInfo(int id)
{
//var deptInfo = await _context.DeptInfoes.FindAsync(id);
ResultModel<DeptInfo> result = new ResultModel<DeptInfo>();
var deptInfo = await _context.DeptInfoes.Where(m => m.DeptID == id).FirstOrDefaultAsync();
if (deptInfo == null)
{
return NotFound();
result.Msg = "部門編號不存在";
result.Success = false;
return result;
}
_context.DeptInfoes.Remove(deptInfo);
await _context.SaveChangesAsync();
return deptInfo;
result.Msg = "OK";
result.Success = true;
return result;
}
private bool DeptInfoExists(int id)

60
AMESCoreStudio.WebApi/Controllers/SYS/ProgramInfoesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -46,14 +47,19 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// GET: api/ProgramInfoes/Module/5
[HttpGet("Module/{id}")]
public async Task<ActionResult<IEnumerable<ProgramInfo>>> GetProgramInfoByModule(int id, int page = 0, int limit = 10)
public async Task<ResultModel<ProgramInfo>> GetProgramInfoByModule(int id, int page = 0, int limit = 10)
{
ResultModel<ProgramInfo> result = new ResultModel<ProgramInfo>();
IQueryable<ProgramInfo> q = _context.ProgramInfoes;
if (id > 0)
{
q = q.Where(p => p.ModuleID.Equals(id));
}
result.DataTotal = q.ToList().Count;
if (page > 0)
{
q = q.OrderBy(p => p.SortSeq).Skip((page - 1) * limit).Take(limit);
@ -67,21 +73,27 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
var programInfo = await q.ToListAsync();
result.Data = programInfo;
if (programInfo == null)
{
return NotFound();
result.Msg = "查無資料";
result.Success = false;
return result;
}
return programInfo;
result.Msg = "OK";
result.Success = true;
return result;
}
catch (Exception e1)
{
string msg = e1.Message;
}
return NotFound();
result.Msg = "OK";
result.Success = true;
return result;
}
@ -121,11 +133,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<ProgramInfo>> PutProgramInfo(int id, [FromBody] ProgramInfo programInfo)
public async Task<ResultModel<ProgramInfo>> PutProgramInfo(int id, [FromBody] ProgramInfo programInfo)
{
ResultModel<ProgramInfo> result = new ResultModel<ProgramInfo>();
if (id != programInfo.ProgramID)
{
return BadRequest();
result.Msg = "程式編號錯誤";
result.Success = false;
return result;
}
_context.Entry(programInfo).State = EntityState.Modified;
@ -138,7 +154,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!ProgramInfoExists(id))
{
return NotFound();
result.Msg = "程式編號不存在";
result.Success = false;
return result;
}
else
{
@ -146,8 +164,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return programInfo;
//return NoContent();
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -159,8 +178,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<ProgramInfo>> PostProgramInfo([FromBody] ProgramInfo programInfo)
public async Task<ResultModel<ProgramInfo>> PostProgramInfo([FromBody] ProgramInfo programInfo)
{
ResultModel<ProgramInfo> result = new ResultModel<ProgramInfo>();
Helper helper = new Helper(_context);
programInfo.ProgramID = helper.GetIDKey("PROGRAM_ID").Result;
@ -170,7 +191,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.ProgramInfoes.Add(programInfo);
await _context.SaveChangesAsync();
return CreatedAtAction("GetProgramInfo", new { id = programInfo.ProgramID }, programInfo);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -180,20 +203,25 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/ProgramInfoes/5
[HttpDelete("{id}")]
public async Task<ActionResult<ProgramInfo>> DeleteProgramInfo(int id)
public async Task<ResultModel<ProgramInfo>> DeleteProgramInfo(int id)
{
//var programInfo = await _context.ProgramInfoes.FindAsync(id);
ResultModel<ProgramInfo> result = new ResultModel<ProgramInfo>();
var programInfo = await _context.ProgramInfoes.Where(m => m.ProgramID == id).FirstOrDefaultAsync();
if (programInfo == null)
{
return NotFound();
result.Msg = "程式編號不存在";
result.Success = false;
return result;
}
_context.ProgramInfoes.Remove(programInfo);
await _context.SaveChangesAsync();
return programInfo;
result.Msg = "OK";
result.Success = true;
return result;
}
private bool ProgramInfoExists(int id)

59
AMESCoreStudio.WebApi/Controllers/SYS/RoleInfoesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -32,10 +33,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// GET: api/RoleInfoes
[HttpGet]
public async Task<ActionResult<IEnumerable<RoleInfo>>> GetRoleInfo(int page = 0, int limit = 10)
public async Task<ResultModel<RoleInfo>> GetRoleInfo(int page = 0, int limit = 10)
{
ResultModel<RoleInfo> result = new ResultModel<RoleInfo>();
IQueryable<RoleInfo> q = _context.RoleInfoes;
q = q.Where(p => p.RoleID > 0);
result.DataTotal = q.ToList().Count;
if (page > 0)
{
q = q.OrderBy(p => p.RoleNo).Skip((page - 1) * limit).Take(limit);
@ -46,9 +52,18 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
var roleInfo = await q.ToListAsync();
return roleInfo;
result.Data = roleInfo;
if (roleInfo == null)
{
result.Msg = "查無資料";
result.Success = false;
return result;
}
//return await _context.RoleInfoes.ToListAsync();
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -84,11 +99,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<RoleInfo>> PutRoleInfo(int id, [FromBody] RoleInfo roleInfo)
public async Task<ResultModel<RoleInfo>> PutRoleInfo(int id, [FromBody] RoleInfo roleInfo)
{
ResultModel<RoleInfo> result = new ResultModel<RoleInfo>();
if (id != roleInfo.RoleID)
{
return BadRequest();
result.Msg = "角色編號錯誤";
result.Success = false;
return result;
}
_context.Entry(roleInfo).State = EntityState.Modified;
@ -101,7 +120,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!RoleInfoExists(id))
{
return NotFound();
result.Msg = "角色編號不存在";
result.Success = false;
return result;
}
else
{
@ -109,8 +130,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return roleInfo;
//return NoContent();
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -122,8 +144,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<RoleInfo>> PostRoleInfo([FromBody] RoleInfo roleInfo)
public async Task<ResultModel<RoleInfo>> PostRoleInfo([FromBody] RoleInfo roleInfo)
{
ResultModel<RoleInfo> result = new ResultModel<RoleInfo>();
Helper helper = new Helper(_context);
roleInfo.RoleID = helper.GetIDKey("ROLE_ID").Result;
roleInfo.CreateDateTime = DateTime.Now;
@ -132,7 +156,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.RoleInfoes.Add(roleInfo);
await _context.SaveChangesAsync();
return CreatedAtAction("GetRoleInfo", new { id = roleInfo.RoleID }, roleInfo);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -142,19 +168,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/RoleInfoes/5
[HttpDelete("{id}")]
public async Task<ActionResult<RoleInfo>> DeleteRoleInfo(int id)
public async Task<ResultModel<RoleInfo>> DeleteRoleInfo(int id)
{
//var roleInfo = await _context.RoleInfoes.FindAsync(id);
ResultModel<RoleInfo> result = new ResultModel<RoleInfo>();
var roleInfo = await _context.RoleInfoes.Where(m => m.RoleID == id).FirstOrDefaultAsync();
if (roleInfo == null)
{
return NotFound();
result.Msg = "角色編號不存在";
result.Success = false;
return result;
}
_context.RoleInfoes.Remove(roleInfo);
await _context.SaveChangesAsync();
return roleInfo;
result.Msg = "OK";
result.Success = true;
return result;
}
private bool RoleInfoExists(int id)

56
AMESCoreStudio.WebApi/Controllers/SYS/RoleModulesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -64,16 +65,19 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// GET: api/RoleModules/Role/5
[HttpGet("Role/{id}")]
public async Task<ActionResult<IEnumerable<RoleModule>>> GetRoleModuleByRole(int id, int page = 0, int limit = 10)
public async Task<ResultModel<RoleModule>> GetRoleModuleByRole(int id, int page = 0, int limit = 10)
{
//IQueryable<RoleModule> q = _context.RoleModules.Include(r=>r.Module);
IQueryable<RoleModule> q = _context.RoleModules;
ResultModel<RoleModule> result = new ResultModel<RoleModule>();
IQueryable<RoleModule> q = _context.RoleModules;
if (id > 0)
{
q = q.Where(p => p.RoleID.Equals(id));
}
result.DataTotal = q.ToList().Count;
if (page > 0)
{
q = q.OrderBy(p => p.ModuleID).Skip((page - 1) * limit).Take(limit);
@ -91,12 +95,18 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
result.Data = roleModule;
if (roleModule == null)
{
return NotFound();
result.Msg = "查無資料";
result.Success = false;
return result;
}
return roleModule;
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -132,11 +142,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<RoleModule>> PutRoleModule(int id, [FromBody] RoleModule roleModule)
public async Task<ResultModel<RoleModule>> PutRoleModule(int id, [FromBody] RoleModule roleModule)
{
ResultModel<RoleModule> result = new ResultModel<RoleModule>();
if (id != roleModule.RoleModuleID)
{
return BadRequest();
result.Msg = "角色模組編號錯誤";
result.Success = false;
return result;
}
_context.Entry(roleModule).State = EntityState.Modified;
@ -162,7 +176,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!RoleModuleExists(id))
{
return NotFound();
result.Msg = "角色模組編號不存在";
result.Success = false;
return result;
}
else
{
@ -170,7 +186,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return roleModule;
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -182,8 +200,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<RoleModule>> PostRoleModule([FromBody] RoleModule roleModule)
public async Task<ResultModel<RoleModule>> PostRoleModule([FromBody] RoleModule roleModule)
{
ResultModel<RoleModule> result = new ResultModel<RoleModule>();
Helper helper = new Helper(_context);
roleModule.RoleModuleID = helper.GetIDKey("ROLE_MODULEID").Result;
if (roleModule.EnableFlag == "Y")
@ -195,7 +215,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.RoleModules.Add(roleModule);
await _context.SaveChangesAsync();
return CreatedAtAction("GetRoleModule", new { id = roleModule.RoleModuleID }, roleModule);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -205,18 +227,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/RoleModules/5
[HttpDelete("{id}")]
public async Task<ActionResult<RoleModule>> DeleteRoleModule(int id)
public async Task<ResultModel<RoleModule>> DeleteRoleModule(int id)
{
ResultModel<RoleModule> result = new ResultModel<RoleModule>();
var roleModule = await _context.RoleModules.Where(m => m.RoleModuleID == id).FirstOrDefaultAsync();
if (roleModule == null)
{
return NotFound();
result.Msg = "角色模組編號不存在";
result.Success = false;
return result;
}
_context.RoleModules.Remove(roleModule);
await _context.SaveChangesAsync();
return roleModule;
result.Msg = "OK";
result.Success = true;
return result;
}

54
AMESCoreStudio.WebApi/Controllers/SYS/RoleProgramsController.cs

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -64,14 +65,19 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// GET: api/RolePrograms/Role/5
[HttpGet("Role/{id}")]
public async Task<ActionResult<IEnumerable<RoleProgram>>> GetRoleProgramByRole(int id, int page = 0, int limit = 10)
public async Task<ResultModel<RoleProgram>> GetRoleProgramByRole(int id, int page = 0, int limit = 10)
{
ResultModel<RoleProgram> result = new ResultModel<RoleProgram>();
IQueryable<RoleProgram> q = _context.RolePrograms;
if (id > 0)
{
q = q.Where(p => p.RoleID.Equals(id));
}
result.DataTotal = q.ToList().Count;
if (page > 0)
{
q = q.OrderBy(p => p.ProgramID).Skip((page - 1) * limit).Take(limit);
@ -88,12 +94,18 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
data.Program = _context.ProgramInfoes.Where(p1 => p1.ProgramID.Equals(data.ProgramID)).FirstOrDefault();
}
result.Data = roleProgram;
if (roleProgram == null)
{
return NotFound();
result.Msg = "查無資料";
result.Success = false;
return result;
}
return roleProgram;
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -129,11 +141,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<RoleProgram>> PutRoleProgram(int id,[FromBody] RoleProgram roleProgram)
public async Task<ResultModel<RoleProgram>> PutRoleProgram(int id,[FromBody] RoleProgram roleProgram)
{
ResultModel<RoleProgram> result = new ResultModel<RoleProgram>();
if (id != roleProgram.RoleProgramID)
{
return BadRequest();
result.Msg = "角色程式編號錯誤";
result.Success = false;
return result;
}
_context.Entry(roleProgram).State = EntityState.Modified;
@ -159,7 +175,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!RoleProgramExists(id))
{
return NotFound();
result.Msg = "角色程式編號不存在";
result.Success = false;
return result;
}
else
{
@ -167,7 +185,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return roleProgram;
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -179,15 +199,19 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<RoleProgram>> PostRoleProgram([FromBody] RoleProgram roleProgram)
public async Task<ResultModel<RoleProgram>> PostRoleProgram([FromBody] RoleProgram roleProgram)
{
ResultModel<RoleProgram> result = new ResultModel<RoleProgram>();
Helper helper = new Helper(_context);
roleProgram.RoleProgramID = helper.GetIDKey("ROLE_PROGRAMID").Result;
_context.RolePrograms.Add(roleProgram);
await _context.SaveChangesAsync();
return CreatedAtAction("GetRoleProgram", new { id = roleProgram.RoleProgramID }, roleProgram);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -197,18 +221,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/RolePrograms/5
[HttpDelete("{id}")]
public async Task<ActionResult<RoleProgram>> DeleteRoleProgram(int id)
public async Task<ResultModel<RoleProgram>> DeleteRoleProgram(int id)
{
ResultModel<RoleProgram> result = new ResultModel<RoleProgram>();
var roleProgram = await _context.RolePrograms.FindAsync(id);
if (roleProgram == null)
{
return NotFound();
result.Msg = "角色程式編號不存在";
result.Success = false;
return result;
}
_context.RolePrograms.Remove(roleProgram);
await _context.SaveChangesAsync();
return roleProgram;
result.Msg = "OK";
result.Success = true;
return result;
}
private bool RoleProgramExists(int id)

60
AMESCoreStudio.WebApi/Controllers/SYS/UserInfoesController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -32,10 +33,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// GET: api/UserInfoes
[HttpGet]
public async Task<ActionResult<IEnumerable<UserInfo>>> GetUserInfo(int page = 0, int limit = 10)
public async Task<ResultModel<UserInfo>> GetUserInfo(int page = 0, int limit = 10)
{
ResultModel<UserInfo> result = new ResultModel<UserInfo>();
IQueryable<UserInfo> q = _context.UserInfoes;
q = q.Where(p => p.UserID > 0);
result.DataTotal = q.ToList().Count;
if (page > 0)
{
q = q.OrderBy(p => p.UserNo).Skip((page - 1) * limit).Take(limit);
@ -46,8 +52,19 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
var userInfo = await q.ToListAsync();
return userInfo;
//return await _context.UserInfoes.ToListAsync();
result.Data = userInfo;
if (userInfo == null)
{
result.Msg = "查無資料";
result.Success = false;
return result;
}
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -95,11 +112,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<UserInfo>> PutUserInfo(int id, [FromBody] UserInfo userInfo)
public async Task<ResultModel<UserInfo>> PutUserInfo(int id, [FromBody] UserInfo userInfo)
{
ResultModel<UserInfo> result = new ResultModel<UserInfo>();
if (id != userInfo.UserID)
{
return BadRequest();
result.Msg = "用戶編號錯誤";
result.Success = false;
return result;
}
_context.Entry(userInfo).State = EntityState.Modified;
@ -115,7 +136,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!UserInfoExists(id))
{
return NotFound();
result.Msg = "用戶編號不存在";
result.Success = false;
return result;
}
else
{
@ -123,8 +146,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return userInfo;
//return NoContent();
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -136,8 +160,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<UserInfo>> PostUserInfo([FromBody] UserInfo userInfo)
public async Task<ResultModel<UserInfo>> PostUserInfo([FromBody] UserInfo userInfo)
{
ResultModel<UserInfo> result = new ResultModel<UserInfo>();
Helper helper = new Helper(_context);
userInfo.UserID = helper.GetIDKey("USER_ID").Result;
userInfo.CreateUserId = 0;
@ -146,7 +172,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.UserInfoes.Add(userInfo);
await _context.SaveChangesAsync();
return CreatedAtAction("GetUserInfo", new { id = userInfo.UserID }, userInfo);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -156,19 +184,25 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/UserInfoes/5
[HttpDelete("{id}")]
public async Task<ActionResult<UserInfo>> DeleteUserInfo(int id)
public async Task<ResultModel<UserInfo>> DeleteUserInfo(int id)
{
ResultModel<UserInfo> result = new ResultModel<UserInfo>();
var userInfo = await _context.UserInfoes.Where(m => m.UserID == id).FirstOrDefaultAsync();
if (userInfo == null)
{
return NotFound();
result.Msg = "用戶編號不存在";
result.Success = false;
return result;
}
_context.UserInfoes.Remove(userInfo);
await _context.SaveChangesAsync();
return userInfo;
result.Msg = "OK";
result.Success = true;
return result;
}
private bool UserInfoExists(int id)

55
AMESCoreStudio.WebApi/Controllers/SYS/UserRolesController.cs

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using AMESCoreStudio.WebApi;
using AMESCoreStudio.WebApi.Models.SYS;
using AMESCoreStudio.CommonTools.Result;
namespace AMESCoreStudio.WebApi.Controllers.SYS
{
@ -59,11 +60,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// 根据用户ID获取该用户角色资料
/// </summary>
/// <param name="id"></param>
/// <param name="page"></param>
/// <param name="limit"></param>
/// <returns></returns>
// GET: api/UserRoles/User/5
[HttpGet("User/{id}")]
public async Task<ActionResult<IEnumerable<UserRole>>> GetUserRoleByUser(int id, int page = 0, int limit = 10)
public async Task<ResultModel<UserRole>> GetUserRoleByUser(int id, int page = 0, int limit = 10)
{
ResultModel<UserRole> result = new ResultModel<UserRole>();
IQueryable<UserRole> q = _context.UserRoles;
if (id > 0)
@ -71,6 +76,8 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
q = q.Where(p => p.UserID.Equals(id));
}
result.DataTotal = q.ToList().Count;
if (page > 0)
{
q = q.OrderBy(p => p.RoleID).Skip((page - 1) * limit).Take(limit);
@ -87,12 +94,18 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
result.Data = userRole;
if (userRole == null)
{
return NotFound();
result.Msg = "查無資料";
result.Success = false;
return result;
}
return userRole;
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -127,11 +140,15 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task<ActionResult<UserRole>> PutUserRole(int id, [FromBody] UserRole userRole)
public async Task<ResultModel<UserRole>> PutUserRole(int id, [FromBody] UserRole userRole)
{
ResultModel<UserRole> result = new ResultModel<UserRole>();
if (id != userRole.UserRoleID)
{
return BadRequest();
result.Msg = "用戶角色編號錯誤";
result.Success = false;
return result;
}
_context.Entry(userRole).State = EntityState.Modified;
@ -157,7 +174,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
{
if (!UserRoleExists(id))
{
return NotFound();
result.Msg = "用戶角色編號不存在";
result.Success = false;
return result;
}
else
{
@ -165,7 +184,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
}
}
return userRole;
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -177,8 +198,10 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task<ActionResult<UserRole>> PostUserRole([FromBody] UserRole userRole)
public async Task<ResultModel<UserRole>> PostUserRole([FromBody] UserRole userRole)
{
ResultModel<UserRole> result = new ResultModel<UserRole>();
Helper helper = new Helper(_context);
userRole.UserRoleID = helper.GetIDKey("USER_ROLEID").Result;
if (userRole.EnableFlag == "Y")
@ -190,7 +213,9 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
_context.UserRoles.Add(userRole);
await _context.SaveChangesAsync();
return CreatedAtAction("GetUserRole", new { id = userRole.UserRoleID }, userRole);
result.Msg = "OK";
result.Success = true;
return result;
}
/// <summary>
@ -200,18 +225,24 @@ namespace AMESCoreStudio.WebApi.Controllers.SYS
/// <returns></returns>
// DELETE: api/UserRoles/5
[HttpDelete("{id}")]
public async Task<ActionResult<UserRole>> DeleteUserRole(int id)
public async Task<ResultModel<UserRole>> DeleteUserRole(int id)
{
ResultModel<UserRole> result = new ResultModel<UserRole>();
var userRole = await _context.UserRoles.Where(m => m.UserRoleID == id).FirstOrDefaultAsync();
if (userRole == null)
{
return NotFound();
result.Msg = "用戶角色編號不存在";
result.Success = false;
return result;
}
_context.UserRoles.Remove(userRole);
await _context.SaveChangesAsync();
return userRole;
result.Msg = "OK";
result.Success = true;
return result;
}
private bool UserRoleExists(int id)

Loading…
Cancel
Save