ABP学习入门系列(五)(展示实现增删改查)
大致要实现的 效果如下
1,添加Controller(用到的X.PagedList 注意到nuget添加)
using System.Web.Mvc;
using Abp.Application.Services.Dto;
using Abp.Runtime.Caching;
using Abp.Threading;
using Abp.Web.Mvc.Authorization;
using AutoMapper;
using LearningMpaAbp.Notifications;
using LearningMpaAbp.Tasks;
using LearningMpaAbp.Tasks.Dtos;
using LearningMpaAbp.Users;
using LearningMpaAbp.Users.Dto;
using LearningMpaAbp.Web.Models.Tasks;
using X.PagedList; namespace LearningMpaAbp.Web.Controllers
{
[AbpMvcAuthorize]
public class TasksController : LearningMpaAbpControllerBase
{
private readonly ITaskAppService _taskAppService;
private readonly IUserAppService _userAppService;
private readonly INotificationAppService _notificationAppService;
private readonly ICacheManager _cacheManager; public TasksController(ITaskAppService taskAppService, IUserAppService userAppService, ICacheManager cacheManager, INotificationAppService notificationAppService)
{
_taskAppService = taskAppService;
_userAppService = userAppService;
_cacheManager = cacheManager;
_notificationAppService = notificationAppService;
} public ActionResult Index(GetTasksInput input)
{
var output = _taskAppService.GetTasks(input); var model = new IndexViewModel(output.Tasks)
{
SelectedTaskState = input.State
};
return View(model);
} // GET: Tasks
public ActionResult PagedList(int? page)
{
//每页行数
var pageSize = 5;
var pageNumber = page ?? 1; //第几页 var filter = new GetTasksInput
{
SkipCount = (pageNumber - 1) * pageSize, //忽略个数
MaxResultCount = pageSize
};
var result = _taskAppService.GetPagedTasks(filter); //已经在应用服务层手动完成了分页逻辑,所以需手动构造分页结果
var onePageOfTasks = new StaticPagedList<TaskDto>(result.Items, pageNumber, pageSize, result.TotalCount);
//将分页结果放入ViewBag供View使用
ViewBag.OnePageOfTasks = onePageOfTasks; return View();
} public PartialViewResult GetList(GetTasksInput input)
{
var output = _taskAppService.GetTasks(input);
return PartialView("_List", output.Tasks);
} /// <summary>
/// 获取创建任务分部视图
/// 该方法使用ICacheManager进行缓存,在WebModule中配置缓存过期时间为10mins
/// </summary>
/// <returns></returns>
public PartialViewResult RemoteCreate()
{
//1.1 注释该段代码,使用下面缓存的方式
//var userList = _userAppService.GetUsers(); //1.2 同步调用异步解决方案(最新Abp创建的模板项目已经去掉该同步方法,所以可以通过下面这种方式获取用户列表)
//var userList = AsyncHelper.RunSync(() => _userAppService.GetUsersAsync()); //1.3 缓存版本
var userList = _cacheManager.GetCache("ControllerCache").Get("AllUsers", () => _userAppService.GetUsers()); //1.4 转换为泛型版本
//var userList = _cacheManager.GetCache("ControllerCache").AsTyped<string, ListResultDto<UserListDto>>().Get("AllUsers", () => _userAppService.GetUsers()); //1.5 泛型缓存版本
//var userList = _cacheManager.GetCache<string, ListResultDto<UserListDto>>("ControllerCache").Get("AllUsers", () => _userAppService.GetUsers()); ViewBag.AssignedPersonId = new SelectList(userList.Items, "Id", "Name");
return PartialView("_CreateTaskPartial");
} /// <summary>
/// 获取创建任务分部视图(子视图)
/// 该方法使用[OutputCache]进行缓存,缓存过期时间为2mins
/// </summary>
/// <returns></returns>
[ChildActionOnly]
[OutputCache(Duration = 1200, VaryByParam = "none")]
public PartialViewResult Create()
{
var userList = _userAppService.GetUsers();
ViewBag.AssignedPersonId = new SelectList(userList.Items, "Id", "Name");
return PartialView("_CreateTask");
} // POST: Tasks/Create
// 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
// 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateTaskInput task)
{
var id = _taskAppService.CreateTask(task); var input = new GetTasksInput();
var output = _taskAppService.GetTasks(input); return PartialView("_List", output.Tasks);
} // GET: Tasks/Edit/5 public PartialViewResult Edit(int id)
{
var task = _taskAppService.GetTaskById(id); var updateTaskDto = Mapper.Map<UpdateTaskInput>(task); var userList = _userAppService.GetUsers();
ViewBag.AssignedPersonId = new SelectList(userList.Items, "Id", "Name", updateTaskDto.AssignedPersonId); return PartialView("_EditTask", updateTaskDto);
} // POST: Tasks/Edit/5
// 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
// 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(UpdateTaskInput updateTaskDto)
{
_taskAppService.UpdateTask(updateTaskDto); var input = new GetTasksInput();
var output = _taskAppService.GetTasks(input); return PartialView("_List", output.Tasks);
} public ActionResult NotifyUser()
{
_notificationAppService.NotificationUsersWhoHaveOpenTask();
return new EmptyResult();
}
}
}
2,视图
@using Abp.Web.Mvc.Extensions
@model LearningMpaAbp.Web.Models.Tasks.IndexViewModel @{
ViewBag.Title = L("TaskList");
ViewBag.ActiveMenu = "TaskList"; //Matches with the menu name in SimpleTaskAppNavigationProvider to highlight the menu item
}
@section scripts{
@Html.IncludeScript("~/Views/Tasks/index.js");
}
<h2>
@L("TaskList") <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add">Create Task</button> <a class="btn btn-primary" data-toggle="modal" href="@Url.Action("RemoteCreate")" data-target="#modal" role="button">(Create Task)使用Remote方式调用Modal进行展现</a> <a class="btn btn-success" href="@Url.Action("PagedList")" role="button">分页展示</a> <button type="button" class="btn btn-info" onclick="notifyUser();">通知未完成任务的用户</button>
<!--任务清单按照状态过滤的下拉框-->
<span class="pull-right">
@Html.DropDownListFor(
model => model.SelectedTaskState,
Model.GetTaskStateSelectListItems(),
new
{
@class = "form-control select2",
id = "TaskStateCombobox"
})
</span>
</h2> <!--任务清单展示-->
<div class="row" id="taskList">
@{ Html.RenderPartial("_List", Model.Tasks); }
</div> <!--通过初始加载页面的时候提前将创建任务模态框加载进来-->
@Html.Action("Create") <!--编辑任务模态框通过ajax动态填充到此div中-->
<div id="edit"> </div> <!--Remote方式弹出创建任务模态框-->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="createTask" data-backdrop="static">
<div class="modal-dialog" role="document">
<div class="modal-content"> </div>
</div>
</div>
另外还有_createTaskPartial,_EditTaskPartial 等,这里就不贴代码了
以上。。。
参考http://www.jianshu.com/p/620c20fa511b
代码地址https://github.com/tianxiangd/LearnAbp
ABP学习入门系列(五)(展示实现增删改查)的更多相关文章
- JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(一)
前言:出于某种原因,需要学习下Knockout.js,这个组件很早前听说过,但一直没尝试使用,这两天学习了下,觉得它真心不错,双向绑定的机制简直太爽了.今天打算结合bootstrapTable和Kno ...
- JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(四):自定义T4模板快速生成页面
前言:上篇介绍了下ko增删改查的封装,确实节省了大量的js代码.博主是一个喜欢偷懒的人,总觉得这些基础的增删改查效果能不能通过一个什么工具直接生成页面效果,啥代码都不用写了,那该多爽.于是研究了下T4 ...
- JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(二)
前言:上篇 JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(一) 介绍了下knockout.js的一些基础用法,由于篇幅的关系,所以只能分成两篇,望见谅!昨天就 ...
- SQLite 入门教程(四)增删改查,有讲究 (转)
转于: SQLite 入门教程(四)增删改查,有讲究 一.插入数据 INSERT INTO 表(列...) VALUES(值...) 根据前面几篇的内容,我们可以很轻送的创建一个数据表,并向其中插入一 ...
- JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(三):两个Viewmodel搞定增删改查
前言:之前博主分享过knockoutJS和BootstrapTable的一些基础用法,都是写基础应用,根本谈不上封装,仅仅是避免了html控件的取值和赋值,远远没有将MVVM的精妙展现出来.最近项目打 ...
- MVC3+EF4.1学习系列(二)-------基础的增删改查和持久对象的生命周期变化
上篇文章中 我们已经创建了EF4.1基于code first的例子 有了数据库 并初始化了一些数据 今天这里写基础的增删改查和持久对象的生命周期变化 学习下原文先把运行好的原图贴来上~~ 一.创建 ...
- SQL Server学习之路(五):“增删改查”之“改”
0.目录 1.前言 2.通过SSMS修改数据 3.通过SQL语句修改数据 3.1 修改单列数据 3.2 修改多列数据 1.前言 增删改查都是对数据的操作,其中"改"对应的SQL语句 ...
- MongoDB入门(介绍、安装、增删改查)
文章作者公众号bigsai,已收录在回车课堂,如有帮助还请不吝啬点个赞赞支持一下! 课程导学 大家好我是bigsai,我们都学过数据库,但你可能更熟悉关系(型)数据库例如MySQL,SQL SERVE ...
- SQLite 入门教程(四)增删改查,有讲究
增删改查操作,其中增删改操作被称为数据操作语言 DML,相对来说简单一点. 查操作相对来说复杂一点,涉及到很多子句,所以这篇先讲增删改操作,以例子为主,后面再讲查操作. 一.插入数据 INSERT I ...
- hibernate系列笔记(1)---Hibernate增删改查
Hibernate增删改查 1.首先我们要知道什么是Hibernate Hibernate是一个轻量级的ORMapping对象.主要用来实现Java和数据库表之间的映射,除此之外还提供数据查询和数据获 ...
随机推荐
- Prism 的 TabControl 导航
基于Prism 7.1 最近工作中可能会用到TabControl所以作为小菜的我提前预习了一下,结果并没有我想的那么简单,于是乎 各种网上查,本来用wpf的人就不多 prism 的可查的资料就更少的可 ...
- Exp4 恶意代码分析 20164321 王君陶
Exp4 恶意代码分析 20164321 王君陶 1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具 ...
- 600. Non-negative Integers without Consecutive Ones
Given a positive integer n, find the number of non-negative integers less than or equal to n, whose ...
- jmeter报错
1.检测服务性能是报超时时问题 解决:因为服务器限制只能域名访问不能用ip+端口访问,但是jmter使用的是IP+端口访问 如图: 所以需要服务器放开这个端口,改成可以使用这个IP+端口访问
- day 51 cooike 与 session
前情提要: cooike 和session 一:cooike 一.会话跟踪技术 1.什么是会话跟踪技术 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可 ...
- Xcode10 libstdc++.6.0.9.tbd移除引起的错误
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/u ...
- NOIP2017滚粗记【上】
Day0: NOIP前停课训练的最后一天,上午打了一场三题都见过的比赛,一窝人AK. 下午一群人在机房缓慢氧化,到了晚上因为比赛在我们学校打,所以所有的机房都断网了(百思不得其解为什么两个竞赛室也被断 ...
- 大数据技术之_19_Spark学习_04_Spark Streaming 应用解析小结
========== Spark Streaming 是什么 ==========1.SPark Streaming 是 Spark 中一个组件,基于 Spark Core 进行构建,用于对流式进行处 ...
- SocketIo+SpringMvc实现文件的上传下载
SocketIo+SpringMvc实现文件的上传下载 socketIo不仅可以用来做聊天工具,也可以实现局域网(当然你如果有外网也可用外网)内实现文件的上传和下载,下面是代码的效果演示: GIT地址 ...
- Tomcat性能调优-让小猫飞奔
一.总结前一天的学习 从“第三天”的性能测试一节中,我们得知了决定性能测试的几个重要指标,它们是: ü 吞吐量 ü Responsetime ü Cpuload ü MemoryUsa ...