Html Code
1 public RoleViewModel generateActionList(string roleId, Listassignidlist) 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 }
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 IListAssignedActions { 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 }