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));
}
}
}

abp(net core)+easyui+efcore仓储系统——展现层实现增删改查之控制器(六)的更多相关文章

  1. abp(net core)+easyui+efcore仓储系统——领域层创建实体(三)

    abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...

  2. abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之列表视图(七)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  3. abp(net core)+easyui+efcore仓储系统——解决方案介绍(二)

    abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) ABP框架 首先介绍一下abp框架,abp其 ...

  4. abp(net core)+easyui+efcore仓储系统——创建应用服务(五)

    abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...

  5. abp(net core)+easyui+efcore仓储系统——定义仓储并实现 (四)

    abp(net core)+easyui+efcore仓储系统目录 abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一) abp(net core)+easyui+e ...

  6. abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一)

    在前面我已经介绍了ASP.NET MVC.ASP.NET Razor.WEBAPI等技术.我准备通过一个实践项目来整体应用一下之前介绍的技术.本系列是介绍基于ABP+EasyUI的Web开发框架的形成 ...

  7. ABP入门系列(6)——展现层实现增删改查

    这一章节将通过完善Controller.View.ViewModel,来实现展现层的增删改查.最终实现效果如下图: 一.定义Controller ABP对ASP.NET MVC Controllers ...

  8. ABP入门系列(5)——展现层实现增删改查

    ABP入门系列目录--学习Abp框架之实操演练 这一章节将通过完善Controller.View.ViewModel,来实现展现层的增删改查.最终实现效果如下图: 一.定义Controller ABP ...

  9. 2019年7月16日 abp(net core)+easyui+efcore实现仓储管理系统——多语言(十)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

随机推荐

  1. 机器学习:scikit-learn 做笑脸识别 (SVM, KNN, Logisitc regression)

    scikit-learn 是 Python 非常强大的一个做机器学习的包,今天介绍scikit-learn 里几个常用的分类器 SVM, KNN 和 logistic regression,用来做笑脸 ...

  2. OpenMP中的同步和互斥

    在多线程编程中必须考虑到不同的线程对同一个变量进行读写访问引起的数据竞争问题.如果线程间没有互斥机制,则不同线程对同一变量的访问顺序是不确定的,有可能导致错误的执行结果. OpenMP中有两种不同类型 ...

  3. WPF图片浏览器(显示大图、小图等)

    原文:WPF图片浏览器(显示大图.小图等) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wangshubo1989/article/details ...

  4. BZOJ 3329 Xorequ 数字DP+矩阵乘法

    标题效果:特定n,乞讨[1,n]内[1,2^n]差多少x满足x^3x=2x x^3x=2x相当于x^2x = 3x 和3x=x+2x 和2x=x<<1 因此x满足条件IFFx&(x ...

  5. MySql 5.7 重置root密码

    一.以安全模式登录 # Stop MySQL sudo service mysql stop # Make MySQL service directory. sudo mkdir -p /var/ru ...

  6. WCF SOAP用法

    基本思路 1.新建一个WCF服务库2.在客户端引用处右键,添加服务引用   点击发现,选择目标服务设置好命名空间   可以在高级一栏里面,设置详细信息   点击确认,添加服务引用 3.在客户端自动生成 ...

  7. DELPHI下多线程编程的几个思维误区(QDAC)

    有几个网友私下问我一些有关线程的事情.过节写个东西上来大家交流. 思维误区1,自己新建的THREAD是线程,自己的主程序不是线程. 很多人在多线程编程没有把主线程也当作线程.其实主线程也是线程.看起来 ...

  8. MultiBinding

    <StackPanel> <Slider x:Name="sl1" Minimum="10" Maximum="100"/ ...

  9. C#代码中设置 控件的触发器

    Style style = new Style(); style.TargetType = typeof(TextBox); MultiDataTrigger trigger = new MultiD ...

  10. Win8 Metro(C#)数字图像处理--2.44图像油画效果算法

    原文:Win8 Metro(C#)数字图像处理--2.44图像油画效果算法  [函数名称]   图像油画效果      OilpaintingProcess(WriteableBitmap src ...