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));
        }
        public ActionResult ManageUserAccountData(UserDetailModel model)
        {
            // Validate
            if (ModelState.IsValid)
            {
                User  user          = null;
                int[] selectedUGIds = null;
                using (var proxy = new UserProxy())
                {
                    user = proxy.GetUserById(model.UserId);
                    User userInfo = @Utilities.GetCurrentUserInfo();
                    if (user != null)
                    {
                        user = new User()
                        {
                            CreatedDate       = user.CreatedDate,
                            UpdatedBy         = Convert.ToString(userInfo.UserName),
                            UpdatedDate       = DateTime.Now,
                            CreatedBy         = user.CreatedBy,
                            Email             = model.Email,
                            Organisation_GUID = model.OrganizationGUID,
                            MobileNumber      = model.OfficeNumber,
                            UserName          = model.UserName,
                            Language          = model.BlastManagerWebSettingID,
                            GUID_User         = user.GUID_User,
                            IsDeptAdmin       = Convert.ToString(model.IsDeptAdmin),
                            IsActive          = Convert.ToByte(model.IsActive),
                            UserDisplayName   = user.UserDisplayName,
                        };

                        model.SelectedUserGroupIdList += string.Join(";", user.UserRoles.Select(p => p.UserRoleId).ToArray());


                        if (!string.IsNullOrWhiteSpace(model.SelectedUserGroupIdList))
                        {
                            user.UserRoles = new List <UserRole>();
                            selectedUGIds  = model.SelectedUserGroupIdList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().Select(p => NumericHelper.ParseInt(p).Value).ToArray();
                            foreach (var ugId in selectedUGIds)
                            {
                                user.UserRoles.Add(new UserRole()
                                {
                                    UserRoleId = ugId
                                });
                            }
                        }
                        proxy.UpdateUser(user);

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

            return(View("ManageUserAccount", model));
        }