From d7f544da5ce7b384717dd0720249c02b221e5515 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 18 Mar 2020 17:00:56 +0800 Subject: [PATCH] update Former-commit-id: d3c853a157c7c757353eb78af0675f68e6af6e39 --- .../Infrastructure/Web/Mvc/BaseController.cs | 2 +- .../Infrastructure/Web/Mvc/CrudController.cs | 30 +++++++++++++++++-- .../Admin/Controlls/Users/UserController.cs | 1 + projects/WebMVC/appsettings.json | 3 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/projects/Infrastructure/Web/Mvc/BaseController.cs b/projects/Infrastructure/Web/Mvc/BaseController.cs index 8c824f1e..a12630bc 100644 --- a/projects/Infrastructure/Web/Mvc/BaseController.cs +++ b/projects/Infrastructure/Web/Mvc/BaseController.cs @@ -2,10 +2,10 @@ using Microsoft.AspNetCore.Mvc; namespace Infrastructure.Web { - [ApiExplorerSettings(IgnoreApi = true)] public class BaseController : Controller { [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1054:URI 参数不应为字符串", Justification = "<挂起>")] + [ApiExplorerSettings(IgnoreApi = true)] public IActionResult RedirectTo(string action = "Index", string controller = null, string rawMesage = "操作成功", object routeValues = null, string returnUrl = null) { if (returnUrl is null) diff --git a/projects/Infrastructure/Web/Mvc/CrudController.cs b/projects/Infrastructure/Web/Mvc/CrudController.cs index a51ba7bc..4e5507ec 100644 --- a/projects/Infrastructure/Web/Mvc/CrudController.cs +++ b/projects/Infrastructure/Web/Mvc/CrudController.cs @@ -12,6 +12,9 @@ using System.Linq; namespace Infrastructure.Web.Mvc { + [ApiExplorerSettings(IgnoreApi = true)] + [ApiController] + [Route("Admin/[controller]/[action]")] public class CrudController : BaseController where TEntity : BaseEntity where TSearchModel : PagedListModel @@ -23,6 +26,7 @@ namespace Infrastructure.Web.Mvc this._repo = repo; } + [HttpGet] public virtual IActionResult Index(TSearchModel model) { if (model == null) @@ -50,9 +54,10 @@ namespace Infrastructure.Web.Mvc .ToList()); ViewData["EntityTypeExt"] = typeof(TEntity); ViewData["ModelTypeExt"] = typeof(TDisplayModel); - return View(model); + return this.Result(model); } + [HttpGet] public virtual IActionResult Details(Guid id) { var query = this._repo.ReadOnlyTable(); @@ -60,9 +65,10 @@ namespace Infrastructure.Web.Mvc var entity = query.FirstOrDefault(o => o.Id == id); var model = entity.To(); this.ToDisplayModel(entity, model); - return View(model); + return Result(model); } + [HttpGet] public virtual IActionResult Add() { var model = Activator.CreateInstance(); @@ -97,6 +103,7 @@ namespace Infrastructure.Web.Mvc return View(model); } + [HttpGet] public virtual IActionResult Edit(Guid id) { var query = this._repo.ReadOnlyTable(); @@ -137,6 +144,7 @@ namespace Infrastructure.Web.Mvc return View(model); } + [HttpPost] public virtual IActionResult Remove(List list) { if (list == null) @@ -161,6 +169,7 @@ namespace Infrastructure.Web.Mvc } } + [HttpPost] public IActionResult Restore(List list) { if (list == null) @@ -185,6 +194,7 @@ namespace Infrastructure.Web.Mvc } } + [HttpPost] public virtual IActionResult Delete(List list) { if (list == null) @@ -212,44 +222,54 @@ namespace Infrastructure.Web.Mvc } } + [ApiExplorerSettings(IgnoreApi = true)] public virtual IQueryable Include(IQueryable query) { return query; } + [ApiExplorerSettings(IgnoreApi = true)] public virtual IQueryable Query(TSearchModel model, IQueryable query) { return query; } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void ToEditModel(TEntity entity, TEditModel model) { } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void ToDisplayModel(TEntity entity, TDisplayModel model) { } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void ToEntity(TEditModel model, TEntity entity) { } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void OnEdit(TEntity entity, TEditModel model) { } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void OnInserted(TEntity entity) { } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void OnUpdated(TEntity entity) { } + [ApiExplorerSettings(IgnoreApi = true)] public virtual void OnDeleted(TEntity entity) { } + [ApiExplorerSettings(IgnoreApi = true)] public override void OnActionExecuting(ActionExecutingContext context) { if (context == null) @@ -291,5 +311,11 @@ namespace Infrastructure.Web.Mvc } } } + + [ApiExplorerSettings(IgnoreApi = true)] + private IActionResult Result(object model) + { + return this.Request.Headers["accept"].ToString().Contains("json") ? Json(model) as IActionResult : View(model); + } } } \ No newline at end of file diff --git a/projects/IoT.Shared/Areas/Admin/Controlls/Users/UserController.cs b/projects/IoT.Shared/Areas/Admin/Controlls/Users/UserController.cs index ea3a9345..5d39bb36 100644 --- a/projects/IoT.Shared/Areas/Admin/Controlls/Users/UserController.cs +++ b/projects/IoT.Shared/Areas/Admin/Controlls/Users/UserController.cs @@ -11,6 +11,7 @@ using System.Linq; namespace IoT.Shared.Areas.Admin.Controllers { + [ApiExplorerSettings(IgnoreApi = false)] [Authorize] [Area(nameof(Admin))] public class UserController : CrudController, EditUserModel, EditUserModel> diff --git a/projects/WebMVC/appsettings.json b/projects/WebMVC/appsettings.json index bb35cdc6..b2409175 100644 --- a/projects/WebMVC/appsettings.json +++ b/projects/WebMVC/appsettings.json @@ -7,5 +7,6 @@ } }, "AllowedHosts": "*", - "server.urls": "http://localhost:5001" + "server.urls": "http://localhost:5001", + "gateway": "http://localhost" } \ No newline at end of file