Up and down selection between 2ge ListBox, MVC ViewModel, 2 geviewmodel

Source: Internet
Author: User

Up and down selection between 2ge ListBox, MVC ViewModel, 2 geviewmodel
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 va R 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 = thi S. 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}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 <ActionViewModel> AssignedActions {get; set;} 10 public IList <ActionViewModel> AvailableActions {get; set;} 11 public string [] AssignedSelect Ed {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 <Acti OnViewModel> (); 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}ViewModel Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.