Esempio n. 1
0
        private void CreateUserGroupService(UserGroupDto NewUserGroup, UserDto currentUser)
        {
            UserGroupServiceClient client = new UserGroupServiceClient();

            try
            {
                if (FormMode == "edit")
                {
                    NewUserGroup.UserGroupId = Id;
                    NewUserGroup             = client.Update(NewUserGroup, currentUser.UserName);
                }
                else
                {
                    NewUserGroup.CreatedBy = currentUser.UserId;
                    NewUserGroup           = client.Create(NewUserGroup, currentUser.UserName);
                }
                if (NewUserGroup.Response.HasWarning)
                {
                    foreach (BusinessWarning businessWarning in NewUserGroup.Response.BusinessWarnings)
                    {
                        ViewData["Error"] = ErrorAndValidationMessages.ResourceManager.GetString(businessWarning.Message);
                    }
                }
                else
                {
                    if (FormMode == "edit")
                    {
                        TempData["GroupSaved"] = String.Format(ClientResources.UserGroupUpdated, NewUserGroup.UserGroupName);
                    }
                    else
                    {
                        TempData["GroupSaved"] = String.Format(ClientResources.UserGroupAdded, NewUserGroup.UserGroupName);
                    }
                    isGroupSaved = true;
                }
            }
            catch (Exception)
            {
                client.Close();
            }
        }
Esempio n. 2
0
        public ActionResult SaveUserGroupRolePermissions(UserGroupRolesModel model)
        {
            UserGroupServiceReference.UserGroupServiceClient UGClient = null;
            UserGroupDto userGroupDto = new UserGroupDto();

            string[] RoleGroupNames = { string.Empty };
            int      usergroupid    = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["usergroupid"]))
            {
                usergroupid = Convert.ToInt32(Request.QueryString["usergroupid"]);
            }

            try
            {
                UGClient       = new UserGroupServiceClient();
                userGroupDto   = UGClient.GetById(usergroupid);
                RoleGroupNames = (string[])Session["RoleGroupNames" + Request.QueryString["usergroupid"]];

                //if (userGroupDto.RolePermissionsInUserGroup == null || userGroupDto.RolePermissionsInUserGroup.Count == 0)
                userGroupDto.RolePermissionsInUserGroup = new List <UserGroupRolePermissionDto>();
                userGroupDto.RolePermissionsInUserGroup.Clear();
                for (int i = 0; i < RoleGroupNames.Count(); i++)
                {
                    List <RoleModel> Roles = (List <RoleModel>)Session[RoleGroupNames[i]];
                    if (Roles != null)
                    {
                        foreach (RoleModel rolemodel in Roles)
                        {
                            if (rolemodel.AllowAdd || rolemodel.AllowEdit || rolemodel.AllowPrint || rolemodel.AllowView || rolemodel.AllowDelete)
                            {
                                var userGroupRolePermissionDto = new UserGroupRolePermissionDto
                                {
                                    PermissionForUserGroup = new List <UserGroupDto>
                                    {
                                        new UserGroupDto
                                        {
                                            UserGroupId = userGroupDto.UserGroupId
                                        }
                                    },
                                    PermissionForRole = rolemodel.PermissionForRole,
                                    AllowAdd          = rolemodel.AllowAdd,
                                    AllowEdit         = rolemodel.AllowEdit,
                                    AllowView         = rolemodel.AllowView,
                                    AllowDelete       = rolemodel.AllowDelete,
                                    AllowPrint        = rolemodel.AllowPrint
                                };
                                userGroupDto.RolePermissionsInUserGroup.Add(userGroupRolePermissionDto);
                            }
                        }
                    }
                }
                UGClient.Update(userGroupDto, ((UserDto)Session[Constants.SKCURRENTUSER]).UserName);
                UGClient.Close();
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }
            finally
            {
                if (RoleGroupNames != null && RoleGroupNames.Count() > 0)
                {
                    for (int i = 0; i < RoleGroupNames.Count(); i++)
                    {
                        Session.Remove(RoleGroupNames[i]);
                    }
                }
                if (Session["RoleGroupNames" + usergroupid] != null)
                {
                    Session.Remove("RoleGroupNames" + usergroupid);
                }
            }
            return(RedirectToAction("UserGroupsIndex", new { usertype = Request.QueryString["usertype"] }));
        }