protected void AllGroupsStore_ReadData(object sender, StoreReadDataEventArgs e) { ListRequest groupsReq = new ListRequest(); groupsReq.Size = "100"; groupsReq.StartAt = "0"; groupsReq.Filter = ""; //Fetching the corresponding list //in this test will take a list of News ListResponse <SecurityGroup> groups = _accessControlService.ChildGetAll <SecurityGroup>(groupsReq); if (!groups.Success) { X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", groups.ErrorCode) != null ? GetGlobalResourceObject("Errors", groups.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + groups.LogId : groups.Summary).Show(); return; } GroupUsersListRequest request = new GroupUsersListRequest(); request.UserId = CurrentUser.Text; ListResponse <SecurityGroupUser> userGroups = _accessControlService.ChildGetAll <SecurityGroupUser>(request); if (!groups.Success) { X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", groups.ErrorCode) != null ? GetGlobalResourceObject("Errors", groups.ErrorCode).ToString() : groups.Summary).Show(); return; } UserGroupsStore.DataSource = userGroups.Items; UserGroupsStore.DataBind(); List <SecurityGroup> availableGroups = new List <SecurityGroup>(); groups.Items.ForEach(x => { if (userGroups.Items.Where(y => y.sgId == x.recordId).Count() == 0) { availableGroups.Add(x); } }); AllGroupsStore.DataSource = availableGroups; AllGroupsStore.DataBind(); GroupsCombo.Select(0); }
public void LeaveGroup(string index) { try { //Step 1 Code to delete the object from the database SecurityGroupUser user = new SecurityGroupUser(); user.userId = CurrentUser.Text; user.sgId = index; PostRequest <SecurityGroupUser> req = new PostRequest <SecurityGroupUser>(); req.entity = user; PostResponse <SecurityGroupUser> r = _accessControlService.ChildDelete <SecurityGroupUser>(req); if (!r.Success) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } else { //Step 2 : remove the object from the store UserGroupsStore.Reload(); AllGroupsStore.Reload(); //Step 3 : Showing a notification for the user Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordDeletedSucc }); } } catch (Exception ex) { //In case of error, showing a message box to the user X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).Show(); } }
protected void SaveGroupUsers(object sender, DirectEventArgs e) { try { //Getting the id to check if it is an Add or an edit as they are managed within the same form. string id = e.ExtraParams["id"]; string selected = e.ExtraParams["selectedGroups"]; List <SecurityGroupUser> selectedUsers = JsonConvert.DeserializeObject <List <SecurityGroupUser> >(selected); selectedUsers.ForEach(x => x.userId = CurrentUser.Text); GroupUsersListRequest request = new GroupUsersListRequest(); request.UserId = CurrentUser.Text; ListResponse <SecurityGroupUser> userGroups = _accessControlService.ChildGetAll <SecurityGroupUser>(request); if (!userGroups.Success) { Common.errorMessage(userGroups); return; } PostRequest <SecurityGroupUser> req = new PostRequest <SecurityGroupUser>(); PostResponse <SecurityGroupUser> resp = new PostResponse <SecurityGroupUser>(); userGroups.Items.ForEach(x => { req.entity = x; resp = _accessControlService.ChildDelete <SecurityGroupUser>(req); if (!resp.Success) { Common.errorMessage(resp); throw new Exception(); } }); //req.entity = new SecurityGroupUser() { sgId = "0", userId = CurrentUser.Text }; //resp = _accessControlService.ChildDelete<SecurityGroupUser>(req); foreach (var item in selectedUsers) { req.entity = item; req.entity.userId = CurrentUser.Text; resp = _accessControlService.ChildAddOrUpdate <SecurityGroupUser>(req); if (!resp.Success) { Common.errorMessage(resp); throw new Exception(); } } Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); groupUsersWindow.Close(); UserGroupsStore.Reload(); } catch (Exception exp) { X.MessageBox.Alert(GetGlobalResourceObject("Common", "Error").ToString(), exp.Message); } }