/// <summary> /// Determines if the current user owns the specified group. /// </summary> /// <param name="group"></param> /// <returns></returns> bool IsUserOwnerOfGroup(Group group) { User user = ArcGISOnlineEnvironment.ArcGISOnline.User.Current; if (user == null) return false; return user.Username == group.Owner; }
/// <summary> /// Creates a "Featured Items" text item for the specified group, associates it with the group and shares it. /// </summary> void CreateFeaturedItemItemForGroup(Group group, EventHandler<ContentItemEventArgs> callback) { List<HttpContentItem> items = new List<HttpContentItem>(); items.Add(new HttpContentItem() { Name = "text", Value = "Featured Items of Group " + group.Id }); items.Add(new HttpContentItem() { Name = "type", Value = "Featured Items" }); items.Add(new HttpContentItem() { Name = "item", Value = "GroupFeaturedItems_" + group.Id }); items.Add(new HttpContentItem() { Name = "overwrite", Value = "true" }); items.Add(new HttpContentItem() { Name = "f", Value = "json" }); //store the Featured Items item on AGOL string url = _agol.Url + "content/users/" + _agol.User.Current.Username + "/addItem?f=json&token=" + _agol.User.Token; WebUtil.MultiPartPostAsync(url, items, ApplicationUtility.Dispatcher, (sender, e) => { ContentItem item = WebUtil.ReadObject<ContentItem>(e.Result); //get the actual ContentItem if (item.Id != null) _agol.Content.GetItem(item.Id, (object sender2, ContentItemEventArgs e2) => { if (e2.Error != null) { if (callback != null) callback(null, new ContentItemEventArgs() { Error = e2.Error }); return; } //set the item's id into the group's featuredItemsId property Update(group.Id, "featuredItemsId", e2.Item.Id, (object sender3, RequestEventArgs e3) => { if (e3.Error != null) { if (callback != null) callback(null, new ContentItemEventArgs() { Error = e3.Error }); return; } //group has been updated successfully //now share the Featured Items item to the group and as public or non public depending if the //group is public or non public string[] groups = { group.Id }; _agol.Content.ShareItem(e2.Item, group.IsPublic, groups, (object sender4, RequestEventArgs e4) => { if (callback != null) callback(null, new ContentItemEventArgs() { Error = e4.Error, Item = e2.Item }); }); }); }); }); }
private void populateGroups(ObservableCollection<BindingWrapper<Group>> wrappers, Group[] groups) { if (groups != null && groups.Length > 0) { foreach (Group group in groups) { BindingWrapper<Group> wrapper = new BindingWrapper<Group>(); wrapper.Content = group; wrapper.Tag = IsUserOwnerOfGroup(group) ? Visibility.Visible : Visibility.Collapsed; wrappers.Add(wrapper); } MyGroupsListBox.ItemsSource = wrappers; MyGroupsListBox.Visibility = Visibility.Visible; SearchResultsTextBlock.Text = string.Format(ESRI.ArcGIS.Mapping.Controls.ArcGISOnline.Resources.Strings.MyGroupControlGroups, groups.Length); } else SearchResultsTextBlock.Text = ESRI.ArcGIS.Mapping.Controls.ArcGISOnline.Resources.Strings.MyGroupControlZeroGroups; }