abp(net core)+easyui+efcore
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之控制器(六)
abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一)
abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二)
abp(net core)+easyui+efcore实现仓储管理系统——领域层创建实体(三)
abp(net core)+easyui+efcore实现仓储管理系统——定义仓储并实现 (四)
abp(net core)+easyui+efcore实现仓储管理系统——创建应用服务(五)
通过前面三篇文章的介绍,我们学习了如何创建实体,如何创建数据库操作,如何创建应用服务。在上一文章中我们在应用层实现了对数据库的CURD操作。在本篇文章中,主要是使用常规的MVC方式来实现增删改查的功能,通过完善Controller、View、ViewModel,以及调试修改控制器来实现展示层的增删改查。最终实现效果如下图:

一、创建ModuleController
ABP对ASP.NET Net Core MVC Controllers进行了集成,通过ABP网站创建的项目会自动创建一个Controller基类,这个Controller基类继承自AbpController, 我们即可使用ABP附加给我们的以下强大功能:
- 本地化
- 异常处理
- 对返回的JsonResult进行包装
- 审计日志
- 权限认证([AbpMvcAuthorize]特性)
- 工作单元(默认未开启,通过添加[UnitOfWork]开启)
我们创建的ABP.TPLMS项目,也同样创建了一个控制器基类,具体位置如下图。

1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击在领域层“ABP.TPLMS.Web.Mvc”项目中的Controller目录。 选择“添加” > “新建项…”。如下图。

2. 在弹出对话框“添加新项-ABP.TPLMS.Web.Mvc”中选择“控制器类”,然后在名称输入框中输入“ModuleController”,然后点击“添加”按钮。如下图。

3.在Visual Studio 2017中打开我们刚才创建ModuleController.cs,并继承自TPLMSControllerBase,并增加列表与修改方法。通过构造函数注入对应用服务的依赖。具体代码如下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.Runtime.Validation;
using ABP.TPLMS.Controllers;
using ABP.TPLMS.Modules;
using ABP.TPLMS.Modules.Dto;
using ABP.TPLMS.Web.Models.Module;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace ABP.TPLMS.Web.Controllers
{ [AbpMvcAuthorize]
public class ModuleController : TPLMSControllerBase
{ // GET: /<controller>/
public IActionResult Index()
{ var output = _moduleAppService.GetAllAsync();
var model = new EditModuleModalViewModel
{
Module = output.Result.Items.First(),
Modules = output.Result.Items
};
return View(model);
} private readonly IModuleAppService _moduleAppService; public ModuleController(IModuleAppService moduleAppService)
{
_moduleAppService = moduleAppService; } [HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateUpdateModuleDto updateDto)
{
_moduleAppService.CreateAsync(updateDto);
var output = _moduleAppService.GetAllAsync();
return PartialView("_List", output.Result);
} public IActionResult Create()
{
return View();
} [HttpPost]
[DisableValidation]
public ActionResult Edit(int id,EditModuleModalViewModel updateDto)
{
if (id != updateDto.Module.Id)
{
return NotFound();
} if (ModelState.IsValid)
{
try
{
var module= AutoMapper.Mapper.Map<CreateUpdateModuleDto>(updateDto.Module); _moduleAppService.UpdateAsync(module); }
catch (DbUpdateConcurrencyException ex)
{
if (!DtoExists(updateDto.Module.Id))
{
return NotFound();
}
else
{
throw ex;
}
}
return RedirectToAction(nameof(Index));
}
return View(updateDto);
} private bool DtoExists(long id)
{
return _moduleAppService.GetAllAsync().Result.Items.Any(e => e.Id == id);
} // GET: Module/Edit/5
public IActionResult Edit(int? id)
{
if (id == null)
{
return NotFound();
} var module = _moduleAppService.GetAllAsync().Result.Items.SingleOrDefault(m => m.Id == id); if (module == null)
{
return NotFound();
}
var model = new EditModuleModalViewModel
{
Module = module
};
return View(model);
//return Ok(cargo.Result);
} // GET: Module/Delete/5
public IActionResult Delete(int? id)
{
if (id == null)
{
return NotFound();
}
var module = _moduleAppService.GetAllAsync().Result.Items.SingleOrDefault(m => m.Id == id); if (module == null)
{
return NotFound();
} var model = new EditModuleModalViewModel
{
Module = AutoMapper.Mapper.Map<CreateUpdateModuleDto>(module)
}; return View(model);
} // POST: Module/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
try
{
await _moduleAppService.DeleteAsync(id);
}
catch (Exception ex)
{
return View(ex.Message);
//throw;
}
return RedirectToAction(nameof(Index));
}
}
}

abp(net core)+easyui+efcore的更多相关文章
- abp(net core)+easyui+efcore仓储系统——解决方案介绍(二)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) ABP框架 首先介绍一下abp框架,abp其 ...
- abp(net core)+easyui+efcore仓储系统——展现层实现增删改查之控制器(六)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore仓储系统——领域层创建实体(三)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore仓储系统——定义仓储并实现 (四)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore仓储系统——创建应用服务(五)
abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之列表视图(七)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- 2019年7月16日 abp(net core)+easyui+efcore实现仓储管理系统——多语言(十)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十一)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
随机推荐
- 学到了林海峰,武沛齐讲的Day18 迭代
x='hello' gxr=iter(x) gxr=x.__iter__() print(next(gxr)) print(gxr.__next__()) iter()===__iter__ next ...
- CF280C Game on Tree 概率与期望
利用期望的线性性,即 $E(a+b)=E(a)+E(b)$. 对于所有点分别求一下期望然后累加即可. code: #include <bits/stdc++.h> #define N 10 ...
- luogu 3380
树状数组套权值线段树 #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- sweiper做一个tab切换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python版本下载时时,官方目录web-based与executable和embeddable 的区别
背景:安装python时不知道选择哪个版本以及他们之间的意思. 1.X86和X86-64的区别:系統是32 bit 的版本还是 64bit 的 2.web-based ,executable , em ...
- 牛客训练21674——牛牛与LCM
Problem 链接:https://ac.nowcoder.com/acm/problem/21674 来源:牛客网 牛牛最近在学习初等数论,他的数学老师给他出了一道题,他觉得太简单了, 懒得做,于 ...
- Jedis API操作redis数据库
1.配置文件 classpath路径下,新建redis.properties配置文件 配置文件内容 # Redis settings redis.host=127.0.0.1 redis.port=6 ...
- 详解DLX及其应用
什么是DLX? 让我们看看百度百科上的解释:在 计算机科学 中, Dancing Links ,舞蹈链, 也叫 DLX, 是由 Donald Knuth 提出的数据结构,目的是快速实现他的 X算法.X ...
- python何时用list,dict,set
从读取的角度来讲: 看是用来随机读取(查询)还是连续读取. list数组集中存放,连续读取效率高(具体还没测试,理论上应该如此). dict散列表,使用hash计算存放的位置,随机读取效率高. 随机读 ...
- GitHub OAuth 第三方登录示例教程
这组 OAuth 系列教程,第一篇介绍了基本概念,第二篇介绍了获取令牌的四种方式,今天演示一个实例,如何通过 OAuth 获取 API 数据. 很多网站登录时,允许使用第三方网站的身份,这称为&quo ...