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.Application.Services.Dto;
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 = AutoMapper.Mapper.Map<CreateUpdateModuleDto>(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(EditModuleModalViewModel updateDto)
{
if (updateDto == null)
{
return NotFound();
}
if (updateDto.Module == null)
{
return NotFound();
}
_moduleAppService.CreateAsync(updateDto.Module); return RedirectToAction(nameof(Index));
}
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= updateDto.Module;
_moduleAppService.UpdateAsync(module); }
catch (DbUpdateConcurrencyException)
{
if (!DtoExists(updateDto.Module.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(updateDto); }
private bool DtoExists(long id)
{
return _moduleAppService.GetAllAsync().Result.Items.Any(e => e.Id == id);
}
// GET: Cargoes/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 = AutoMapper.Mapper.Map<CreateUpdateModuleDto>(module)
};
return View(model);
//return Ok(cargo.Result);
} // GET: Cargoes/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: Cargoes/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));
}
}
}

最新文章

  1. (转)高效的将excel导入sqlserver中
  2. 关于http请求
  3. 初步认识shell
  4. html+css--水平居中总结(不定宽块状元素方法)(一)
  5. Unity3d 动态批处理的问题
  6. HDU 5679 Substring 后缀数组判重
  7. Struts2的struts.properties文件在哪儿啊?
  8. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.3
  9. 反编译工具 使用.NET JustDecompile来反编译你的程序代码
  10. 与Scheme共舞
  11. 基于eclipse的mybatis映射代码自动生成的插件
  12. MS13-069(CVE-2013-3205) CCaret use-after-free Vulnerability Analysis (2014.9)
  13. Zabbix实战-简易教程--动作(Actions)--自动注册
  14. bzoj3894
  15. IL中间语言指令大全
  16. Python基础点
  17. 【SPL标准库专题(5)】 Datastructures:SplStack &amp; SplQueue
  18. go语言之行--数组、切片、map
  19. SpringBoot自动配置xxxAutoConfiguration 的使用
  20. dhroid - Dhdb orm简化sqlite数据库操作

热门文章

  1. pushbutton成为可点击的图标(实现全透明,不论点击与否都只显示Icon)(也就是一个万能控件)
  2. 解决无法定位程序输入点SymEnumSymbols于动态链接库dbghelp.dll
  3. 系统性能指标之 vmstat
  4. /var/tmp/.oracle 和 oracle listener (监听)的一点理解
  5. 微信公众平台消息接口开发(26)从Hello2BizUser文本到subscribe事件
  6. Delphi 快速获取文件大小(使用_lopen和FileSeek,此函数可以快速获取文件大小,即使文件已经被其它程序锁定)
  7. Akka边学边写(1)-- Hello, World!
  8. (转)总结:JavaScript异步、事件循环与消息队列、微任务与宏任务
  9. cocos2d-x 在XML分析和数据存储
  10. 安装在谷歌axure小工具