Exemple #1
0
        public void UpdateById(int id, TEntityType entity, ListUpdateOptions options = ListUpdateOptions.None)
        {
            var item = List.GetItemById(id);

            mapper.MapEntityToItem(entity, item);
            item.Update();

            if ((options & ListUpdateOptions.DoNotExecuteQuery) != ListUpdateOptions.DoNotExecuteQuery)
            {
                List.Context.ExecuteQuery();
            }
        }
        public AdditionalInfo Update(Guid listId,
                                     [Documentation(Name = "Title", Type = typeof(string)),
                                      Documentation(Name = "Description", Type = typeof(string)),
                                      Documentation(Name = "DefaultViewId", Type = typeof(Guid))]
                                     IDictionary options)
        {
            var result = new AdditionalInfo();

            if (options == null)
            {
                return(result);
            }

            var updateOptions = new ListUpdateOptions(listId);

            if (options["Title"] != null)
            {
                updateOptions.Title = options["Title"].ToString();
            }
            if (options["Description"] != null)
            {
                updateOptions.Description = options["Description"].ToString();
            }
            if (options["DefaultViewId"] is Guid)
            {
                updateOptions.DefaultViewId = (Guid)options["DefaultViewId"];
            }
            if (updateOptions.Title != null ||
                updateOptions.Description != null ||
                updateOptions.DefaultViewId != Guid.Empty)
            {
                try
                {
                    PublicApi.Lists.Update(updateOptions);
                }
                catch (SPInternalException ex)
                {
                    result.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointListExtension.Translations.CannotBeUpdated)));
                }
                catch (Exception ex)
                {
                    string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointList.Update() method while updating list with Id: {1}. The exception message is: {2}", ex.GetType(), listId, ex.Message);
                    SPLog.UnKnownError(ex, message);
                    result.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointListExtension.Translations.UnknownError)));
                }
            }
            return(result);
        }
Exemple #3
0
        public void Update(TEntityType entity, ListUpdateOptions options = ListUpdateOptions.None)
        {
            var id = mapper.GetId(entity);

            UpdateById(id, entity, options);
        }