public ActionResult ManageAccessControl(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(HttpNotFound());
            }

            AccessControlDetailModel model = new AccessControlDetailModel();

            using (var egProxy = new UserProxy())
            {
                var eg = egProxy.GetSiteMapById(NumericHelper.ParseInt(id).Value);
                if (eg == null)
                {
                    return(HttpNotFound());
                }
                if (eg.ParentId != null && eg.ParentId.HasValue)
                {
                    var parent = egProxy.GetSiteMapById(eg.ParentId.Value);
                    model.SiteMapName = eg.Description + "/" + eg.Description;
                }
                else
                {
                    model.SiteMapName = eg.Description;
                }
                model.Description     = eg.Description;
                model.Depth           = eg.Depth;
                model.MinimumRoleType = eg.MinimumRoleType;
                model.SiteMapId       = NumericHelper.ParseInt(id).Value;
                model.UserGroups      = eg.UserRoles.ToList();
                model.SetUserRoleList((int)eg.MinimumRoleType);
            }

            using (var proxy = new CommonProxy())
            {
                var ht = proxy.GetAllSystemTypes();
                Dictionary <string, string> dic = new Dictionary <string, string>();

                foreach (RoleType en in Enum.GetValues(typeof(RoleType)))
                {
                    if (en != RoleType.None)
                    {
                        string key = StringHelper.Format("{0}.{1}", Constants.SystemTypeCategory.RoleType, (int)en);
                        dic.Add((StringHelper.ToString((int)en)), ht[key] as string);
                    }
                }

                model.DicRoleType = dic;
            }
            return(View(model));
        }
        public ActionResult ManageAccessControlData(AccessControlDetailModel model)
        {
            // Reset model error
            model.Reset();
            SiteMap eg = new SiteMap();

            using (var proxy = new CommonProxy())
            {
                var ht = proxy.GetAllSystemTypes();
                Dictionary <string, string> dic = new Dictionary <string, string>();

                foreach (RoleType en in Enum.GetValues(typeof(RoleType)))
                {
                    if (en != RoleType.None)
                    {
                        string key = StringHelper.Format("{0}.{1}", Constants.SystemTypeCategory.RoleType, (int)en);
                        dic.Add((StringHelper.ToString((int)en)), ht[key] as string);
                    }
                }

                model.DicRoleType = dic;
            }
            using (var egProxy = new UserProxy())
            {
                eg = egProxy.GetSiteMapById(model.SiteMapId);
                if (eg == null)
                {
                    return(HttpNotFound());
                }

                // They will not post back
                if (eg.ParentId != null && eg.ParentId.HasValue)
                {
                    model.SiteMapName = eg.Description + "/" + eg.Description;
                }
                else
                {
                    model.SiteMapName = eg.Description;
                }
                model.Description     = eg.Description;
                model.Depth           = eg.Depth;
                model.MinimumRoleType = eg.MinimumRoleType;
                model.SiteMapId       = eg.SiteMapId;
                model.UserGroups      = eg.UserRoles.ToList();
                model.SetUserRoleList((int)eg.MinimumRoleType);
            }

            // Validate
            if (ModelState.IsValid)
            {
                var selectedUGId = model.UserRoleIdList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().Select(p => NumericHelper.ParseInt(p).Value).ToList();
                eg.UserRoles = new List <UserRole>();

                using (var proxy = new UserProxy())
                {
                    foreach (int id in selectedUGId)
                    {
                        eg.UserRoles.Add(proxy.GetUserGroupById(id));
                    }
                }
                using (var egProxy = new UserProxy())
                {
                    SiteMap sitemap = egProxy.UpdateAccessControl(eg);
                    model.UserGroups = sitemap.UserRoles.ToList();
                }

                model.ShowSuccessMessage   = true;
                model.SuccessDirectionPath = StringHelper.Format("{0}/{1}", Constants.Controllers.User, Constants.Controllers.User_AccessControl);
                model.SuccessMessage       = Convert.ToString(Resources.Res.RES_Success);
            }
            return(View(model));
        }