Abclearning entry series (5) (display to add, delete, modify, and query)
The general effect is as follows:
1. Add Controller (the X. PagedList used is noted that nuget is added)
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. communications; 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 {[Role] public class TasksController: Role {private readonly ITaskAppService _ taskAppService; private readonly IUserAppService _ userAppService; private readonly INotificationAppService _ icationicationappservice; private readonly extends _ cacheManager; public TasksController (taskAppService, IUserAppService userAppService, ICacheManager cacheMa Nager, 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 (mode L);} // GET: Tasks public ActionResult PagedList (int? Page) {// The number of lines per page var pageSize = 5; var pageNumber = page ?? 1; // page number var filter = new GetTasksInput {SkipCount = (pageNumber-1) * pageSize, // ignore the number of MaxResultCount = pageSize}; var result = _ taskAppService. getPagedTasks (filter); // The paging logic has been manually completed at the application service layer. Therefore, you need to manually construct the paging result var onePageOfTasks = new StaticPagedList <TaskDto> (result. items, pageNumber, pageSize, result. totalCount); // puts the paging result into ViewBag for the View to use ViewBag. onePageOfTasks = onePageOfTasks; return View ();} public Pa RtialViewResult GetList (GetTasksInput input) {var output = _ taskAppService. getTasks (input); return PartialView ("_ List", output. tasks) ;}/// <summary> /// obtain the view of creating a task segment /// This method uses ICacheManager for caching, configure the cache expiration time in WebModule as 10 mins /// </summary> /// <returns> </returns> public PartialViewResult RemoteCreate () {// 1.1 comment on the code section, use the following cache method/var userList = _ userAppService. getUsers (); // 1.2 call the asynchronous solution synchronously (the template project created in the latest Abp has After removing this synchronization method, you can obtain the user list using the following method) // var userList = AsyncHelper. runSync () => _ userAppService. getUsersAsync (); // 1.3 cached version var userList = _ cacheManager. getCache ("ControllerCache "). get ("AllUsers", () => _ userAppService. getUsers (); // 1.4 convert to a generic version // var userList = _ cacheManager. getCache ("ControllerCache "). asTyped <string, ListResultDto <UserListDto> (). get ("AllUsers", () => _ userAppService. getUsers (); // 1.5. Generic Cache version // var userList = _ cacheManager. getCache <string, ListResultDto <UserListDto> ("ControllerCache "). get ("AllUsers", () => _ userAppService. getUsers (); ViewBag. assignedPersonId = new SelectList (userList. items, "Id", "Name"); return PartialView ("_ CreateTaskPartial"); }/// <summary> // obtain the view of creating a task segment (subview) /// This method uses [OutputCache] for caching. The cache expiration time is 2 mins /// </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 // to prevent "too many releases" attacks, enable specific properties to bind, see 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 <UpdateTa SkInput> (task); var userList = _ userAppService. getUsers (); ViewBag. assignedPersonId = new SelectList (userList. items, "Id", "Name", updateTaskDto. assignedPersonId); return PartialView ("_ EditTask", updateTaskDto);} // POST: Tasks/Edit/5 // to prevent "too many releases" attacks, enable specific properties to bind, see 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 policyuser () {_ icationicationappservice. notificationUsersWhoHaveOpenTask (); return new EmptyResult ();}}}
2. View
@ 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-primary" data-toggle = "modal" data-target = "# add"> Create Task </button> <a class = "btn-primary" data-toggle = "modal" href = "@ Url. action ("RemoteCreate") "data-target =" # modal "role =" button "> (Create Task) call Modal in Remote mode for presentation </a> <a class = "btn-success" href = "@ Url. action ("PagedList") "role =" button "> display by page </a> <button type = "Button" class = "btn-info" onclick = "yyuser ();"> notify users who have not completed the task </button> <! -- Drop-down list of tasks filtered by status --> <span class = "pull-right"> @ Html. dropDownListFor (model => model. selectedTaskState, Model. getTaskStateSelectListItems (), new {@ class = "form-control select2", id = "TaskStateCombobox"}) </span>
There are also _ createTaskPartial, _ EditTaskPartial, and so on. No code will be posted here.
Above...
Reference http://www.jianshu.com/p/620c20fa511b
Code address https://github.com/tianxiangd/LearnAbp