public ActionResult Role_Edit(EditRoleViewModel model)
        {
            U_Role _role;

            if (model.RoleId == -1)
            {
                _role = new U_Role() { Name = model.RoleName };
                _inFlowDb.U_Roles.Add(_role);
                _inFlowDb.SaveChanges();
            }
            else
            {
                _role = _inFlowDb.U_Roles.Find(model.RoleId);
            }

            if (!_role.Name.Equals(model.RoleName))
            {
                _role.Name = model.RoleName;
            }

            List<int> oldAssignedGroups = new List<int>();
            List<int> newAssignedGroups = new List<int>();

            if (model.SelectedGroups != null)
            {
                (new List<string>(model.SelectedGroups)).ForEach(id => newAssignedGroups.Add(Int16.Parse(id)));
            }

            _role.FunctionGroups.ToList().ForEach(g => oldAssignedGroups.Add(g.Id));

            List<int> groupsToAssign = new List<int>(newAssignedGroups.Except(oldAssignedGroups));

            List<int> groupsToRemove = new List<int>(oldAssignedGroups.Except(newAssignedGroups));

            groupsToAssign.ForEach(group => _role.FunctionGroups.Add(_inFlowDb.U_FunctionGroups.Find(group)));

            groupsToRemove.ForEach(group => _role.FunctionGroups.Remove(_inFlowDb.U_FunctionGroups.Find(group)));

            _inFlowDb.SaveChanges();

            return RedirectToAction("GroupsRoles");
        }
        public ActionResult Role_Edit(int id)
        {
            U_Role _role;
            if (id == -1)
            {
                _role = new U_Role { Id = -1 };
            }
            else
            {
                _role = _inFlowDb.U_Roles.Find(id);
            }
            

            EditRoleViewModel model = new EditRoleViewModel { RoleId = _role.Id, RoleName = _role.Name };

            _role.FunctionGroups.ToList().ForEach(g => model.Groups.Add(new ListViewItemModel { Id = g.Id, Name = g.Name, Selected = true }));
            _inFlowDb.U_FunctionGroups.ToList().Except(_role.FunctionGroups.ToList()).ToList().ForEach(g => model.Groups.Add(new ListViewItemModel { Id = g.Id, Name = g.Name, Selected = false }));

            return View(model);
        }