首页 > 代码库 > 2ge ListBox 之间的 上下选择,MVC ViewModel
2ge ListBox 之间的 上下选择,MVC ViewModel
HtmlCode
1 public RoleViewModel generateActionList(string roleId, List<string> assignidlist) 2 { 3 if (string.IsNullOrEmpty(roleId) && assignidlist == null) 4 { 5 List<IcActions> availableList = this.ServiceLocator.GetService<IRoleActionService>().GetAllActions(appid); 6 List<IcActions> assignList = new List<IcActions>(); 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<IcActions> availableList = this.ServiceLocator.GetService<IRoleActionService>().GetAllActions(appid);13 List<IcActions> assignList = this.ServiceLocator.GetService<IRoleActionService>().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<IIcRolesService>().GetRoleById(roleId);26 List<IcActions> availableList = this.ServiceLocator.GetService<IRoleActionService>().GetAllActions(appid);27 List<IcActions> assignList = this.ServiceLocator.GetService<IRoleActionService>().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 }
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<ActionViewModel> AssignedActions { get; set; } 10 public IList<ActionViewModel> 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<IcActions> assignedList, List<IcActions> availableList)15 {16 var role = new RoleViewModel17 {18 Id = item.RoleId,19 Name = item.RoleName20 };21 22 role.AssignedActions = new List<ActionViewModel>();23 role.AvailableActions = new List<ActionViewModel>();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<ActionViewModel>();61 }62 public void AddAction(ActionViewModel item)63 {64 AssignedActions.Add(item);65 }66 }
2ge ListBox 之间的 上下选择,MVC ViewModel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。