博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2ge ListBox 之间的 上下选择,MVC ViewModel
阅读量:5152 次
发布时间:2019-06-13

本文共 3806 字,大约阅读时间需要 12 分钟。

Html
Code 
1 public RoleViewModel generateActionList(string roleId, List
assignidlist) 2 { 3 if (string.IsNullOrEmpty(roleId) && assignidlist == null) 4 { 5 List
availableList = this.ServiceLocator.GetService
().GetAllActions(appid); 6 List
assignList = new List
(); 7 PortalProj.Common.Entities.IcRoles icRoles = new PortalProj.Common.Entities.IcRoles(); 8 return RoleViewModel.GetFromIcRoles(icRoles, assignList, availableList); 9 }10 else if (string.IsNullOrEmpty(roleId) && assignidlist != null)11 {12 List
availableList = this.ServiceLocator.GetService
().GetAllActions(appid);13 List
assignList = this.ServiceLocator.GetService
().GetActionById(assignidlist).OrderBy(m => m.ActionSeq).ToList();14 PortalProj.Common.Entities.IcRoles icRoles = new PortalProj.Common.Entities.IcRoles();15 foreach (var item in assignList)16 {17 var itemToRemove = availableList.Single(i => i.ActionId == item.ActionId);18 if (itemToRemove != null)19 availableList.Remove(itemToRemove);20 }21 return RoleViewModel.GetFromIcRoles(icRoles, assignList, availableList);22 }23 else24 {25 PortalProj.Common.Entities.IcRoles icRoles = this.ServiceLocator.GetService
().GetRoleById(roleId);26 List
availableList = this.ServiceLocator.GetService
().GetAllActions(appid);27 List
assignList = this.ServiceLocator.GetService
().GetActionById(assignidlist).OrderBy(m => m.ActionSeq).ToList();28 foreach (var item in assignList)29 {30 var itemToRemove = availableList.Single(i => i.ActionId == item.ActionId);31 if (itemToRemove != null)32 availableList.Remove(itemToRemove);33 }34 return RoleViewModel.GetFromIcRoles(icRoles, assignList, availableList);35 }36 }
Function Code
1 public class RoleViewModel 2     { 3         public string Id { get; set; } 4  5         [Required(ErrorMessage = "'Role' cannot be empty.")] 6         public string Name { get; set; } 7  8         [Required(ErrorMessage = "'Selected Functions' cannot be empty.")] 9         public IList
AssignedActions { get; set; } 10 public IList
AvailableActions { get; set; }11 public string[] AssignedSelected { get; set; }12 public string[] AvailableSelected { get; set; }13 14 public static RoleViewModel GetFromIcRoles(PortalProj.Common.Entities.IcRoles item, List
assignedList, List
availableList)15 {16 var role = new RoleViewModel17 {18 Id = item.RoleId,19 Name = item.RoleName20 };21 22 role.AssignedActions = new List
();23 role.AvailableActions = new List
();24 25 if (assignedList != null)26 {27 foreach (var assigned in assignedList)28 {29 var a = new ActionViewModel30 {31 Id = assigned.ActionId,32 Code = assigned.ActionCode,33 Name =Convert.ToString(assigned.ActionSeq)+ "." + assigned.ActionDesc34 };35 36 role.AssignedActions.Add(a);37 }38 }39 40 if (availableList != null)41 {42 foreach (var available in availableList)43 {44 var a = new ActionViewModel45 {46 Id = available.ActionId,47 Code = available.ActionCode,48 Name = Convert.ToString(available.ActionSeq) + "." + available.ActionDesc49 };50 51 role.AvailableActions.Add(a);52 }53 }54 55 return role;56 }57 58 public RoleViewModel()59 {60 AssignedActions = new List
();61 }62 public void AddAction(ActionViewModel item)63 {64 AssignedActions.Add(item);65 }66 }
ViewModel Code

 

转载于:https://www.cnblogs.com/ganguoyu/p/4112843.html

你可能感兴趣的文章
面试时被问到的问题
查看>>
注解小结
查看>>
list control控件的一些操作
查看>>
判断字符串在字符串中
查看>>
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
CSS属性值currentColor
查看>>
Real-Time Rendering 笔记
查看>>
实验四2
查看>>
多路复用
查看>>
Python数据可视化之Pygal(雷达图)
查看>>
Java学习笔记--字符串和文件IO
查看>>
转 Silverlight开发历程—(画刷与着色之线性渐变画刷)
查看>>
在js在添版本号
查看>>
sublime3
查看>>
Exception Type: IntegrityError 数据完整性错误
查看>>
Nuget:Newtonsoft.Json
查看>>
Hdu - 1002 - A + B Problem II
查看>>