Exemplo n.º 1
0
        public ActionResult CreateUserGroupData(UserGroupDetailModel model)
        {
            // Validate
            if (ModelState.IsValid)
            {
                List <SiteMap> siteMapList     = new List <SiteMap>();
                List <SiteMap> siteMapRoleList = new List <SiteMap>();
                SiteMap        list            = new SiteMap();
                UserRole       userRole        = null;
                using (var proxy = new UserProxy())
                {
                    if (proxy.CheckUserGroupExist(model.UserGroupName))
                    {
                        ModelState.AddModelError("User Group Name", Convert.ToString(Resources.Res.RES_Error_Unique));
                    }
                    else
                    {
                        using (var _proxy = new UserProxy())
                        {
                            if ((Utilities.MaxRoleType == RoleType.SystemAdmin) && (Utilities.MaxRoleType != 0))
                            {
                                if (Convert.ToInt32(model.RoleTypeId) == Convert.ToInt32(RoleType.SystemAdmin))
                                {
                                    siteMapList = _proxy.GetSiteMapByApplicationId(1);
                                }
                                if (Convert.ToInt32(model.RoleTypeId) == Convert.ToInt32(RoleType.UserAdmin))
                                {
                                    siteMapRoleList = _proxy.GetSiteMapByApplicationId(1);
                                    foreach (var UserAdminSitmap in siteMapRoleList)
                                    {
                                        if ((UserAdminSitmap.SiteMapTitle == Constants.Controllers.Users) || (UserAdminSitmap.SiteMapTitle == Constants.Controllers.Sitmap_Organization) || (UserAdminSitmap.SiteMapTitle == Constants.Controllers.UserAccount) ||
                                            (UserAdminSitmap.SiteMapTitle == Constants.Controllers.UserGroup))
                                        {
                                            list = _proxy.GetSiteMapBySiteMapById(UserAdminSitmap.SiteMapId);
                                            siteMapList.Add(list);
                                        }
                                    }
                                }
                                else if (Convert.ToInt32(model.RoleTypeId) == Convert.ToInt32(RoleType.NormalUser))
                                {
                                    siteMapRoleList = _proxy.GetSiteMapByApplicationId(1);
                                    foreach (var UserAdminSitmap in siteMapRoleList)
                                    {
                                        if ((UserAdminSitmap.SiteMapTitle == Constants.Controllers.Users) || (UserAdminSitmap.SiteMapTitle == Constants.Controllers.UserAccount))
                                        {
                                            list = _proxy.GetSiteMapBySiteMapById(UserAdminSitmap.SiteMapId);
                                            siteMapList.Add(list);
                                        }
                                    }
                                }

                                else if (Convert.ToInt32(model.RoleTypeId) == Convert.ToInt32(RoleType.RigUser))
                                {
                                    siteMapRoleList = _proxy.GetSiteMapByApplicationId(1);
                                    foreach (var UserAdminSitmap in siteMapRoleList)
                                    {
                                        if ((UserAdminSitmap.SiteMapTitle == Constants.Controllers.Users) || (UserAdminSitmap.SiteMapTitle == Constants.Controllers.UserAccount))
                                        {
                                            list = _proxy.GetSiteMapBySiteMapById(UserAdminSitmap.SiteMapId);
                                            siteMapList.Add(list);
                                        }
                                    }
                                }
                            }
                        }

                        User user = @Utilities.GetCurrentUserInfo();

                        userRole = new UserRole()
                        {
                            Description = Convert.ToString(model.Description),
                            RoleName    = Convert.ToString(model.UserGroupName),
                            RoleType    = model.RoleTypeId.Value,
                            IsADGroup   = false,
                            SiteMaps    = siteMapList,
                            CreatedBy   = Convert.ToString(user.UserName),
                            CreatedDate = DateTime.Now,
                            UpdatedBy   = null,
                            UpdatedDate = null,
                        };
                        proxy.CreateUserGroup(userRole, user);

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