HtmlCode
1 PublicRoleviewmodel Generateactionlist (stringRoleid, list<string>assignidlist)2 {3 if(string. IsNullOrEmpty (roleid) && assignidlist = =NULL)4 {5List<icactions> availablelist = This. Servicelocator.getservice<iroleactionservice>(). Getallactions (AppID);6List<icactions> assignlist =NewList<icactions>();7PortalProj.Common.Entities.IcRoles Icroles =NewPortalProj.Common.Entities.IcRoles ();8 returnroleviewmodel.getfromicroles (Icroles, Assignlist, availablelist);9 }Ten Else if(string. IsNullOrEmpty (Roleid) && assignidlist! =NULL) One { AList<icactions> availablelist = This. Servicelocator.getservice<iroleactionservice>(). Getallactions (AppID); -List<icactions> assignlist = This. Servicelocator.getservice<iroleactionservice> (). Getactionbyid (assignidlist). (M =m.actionseq). ToList (); -PortalProj.Common.Entities.IcRoles Icroles =NewPortalProj.Common.Entities.IcRoles (); the foreach(varIteminchassignlist) - { - varItemtoremove = Availablelist.single (i = I.actionid = =item. ActionId); - if(Itemtoremove! =NULL) + Availablelist.remove (itemtoremove); - } + returnroleviewmodel.getfromicroles (Icroles, Assignlist, availablelist); A } at Else - { -PortalProj.Common.Entities.IcRoles Icroles = This. Servicelocator.getservice<iicrolesservice>(). Getrolebyid (Roleid); -List<icactions> availablelist = This. Servicelocator.getservice<iroleactionservice>(). Getallactions (AppID); -List<icactions> assignlist = This. Servicelocator.getservice<iroleactionservice> (). Getactionbyid (assignidlist). (M =m.actionseq). ToList (); - foreach(varIteminchassignlist) in { - varItemtoremove = Availablelist.single (i = I.actionid = =item. ActionId); to if(Itemtoremove! =NULL) + Availablelist.remove (itemtoremove); - } the returnroleviewmodel.getfromicroles (Icroles, Assignlist, availablelist); * } $}
Function Code
1 Public classRoleviewmodel2 {3 Public stringId {Get;Set; }4 5[Required (errormessage ="' Role ' cannot be empty.")]6 Public stringName {Get;Set; }7 8[Required (errormessage ="' Selected Functions ' cannot be empty.")]9 PublicIlist<actionviewmodel> Assignedactions {Get;Set; } Ten PublicIlist<actionviewmodel> Availableactions {Get;Set; } One Public string[] assignedselected {Get;Set; } A Public string[] availableselected {Get;Set; } - - Public StaticRoleviewmodel getfromicroles (PortalProj.Common.Entities.IcRoles item, list<icactions> assignedlist, list< Icactions>availablelist) the { - varRole =NewRoleviewmodel - { -Id =item. Roleid, +Name =item. RoleName - }; + ARole. Assignedactions =NewList<actionviewmodel>(); atRole. Availableactions =NewList<actionviewmodel>(); - - if(Assignedlist! =NULL) - { - foreach(varAssignedinchassignedlist) - { in varA =NewActionviewmodel - { toId =assigned. ActionId, +Code =assigned. Actioncode, -Name =convert.tostring (assigned. ACTIONSEQ) +"."+assigned. Actiondesc the }; * $ role. Assignedactions.add (a);Panax Notoginseng } - } the + if(Availablelist! =NULL) A { the foreach(varAvailableinchavailablelist) + { - varA =NewActionviewmodel $ { $Id =available. ActionId, -Code =available. Actioncode, -Name = Convert.ToString (available. ACTIONSEQ) +"."+available. Actiondesc the }; - Wuyi role. Availableactions.add (a); the } - } Wu - returnrole; About } $ - PublicRoleviewmodel () - { -Assignedactions =NewList<actionviewmodel>(); A } + Public voidaddaction (Actionviewmodel Item) the { - Assignedactions.add (item); $ } the}
ViewModel Code
Top-down selection between 2ge ListBox, MVC ViewModel