Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }