コード例 #1
0
ファイル: SPListBase.cs プロジェクト: jpavlov/OGE-450
        public virtual T Save()
        {
            ListItem newItem;

            try
            {
                SPContext = new ClientContext(SharePointHelper.Url);

                var web  = SharePointHelper.GetWeb(SPContext);
                var list = SharePointHelper.GetList(SPContext, web, ListName);

                if (Id == 0)
                {
                    // Create
                    var itemCreateInfo = new ListItemCreationInformation();
                    newItem = list.AddItem(itemCreateInfo);
                }
                else
                {
                    // Update
                    newItem = list.GetItemById(Id);
                }

                MapToList(newItem);
                newItem.Update();
                SPContext.Load(newItem);
                SPContext.ExecuteQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to save " + ListName + " with id " + Id + ". " + ex.Message);
            }

            return(Get(newItem.Id));
        }
コード例 #2
0
ファイル: SPListBase.cs プロジェクト: jpavlov/OGE-450
        public static List <T> GetAllBy(string key, string value, bool notEqual = false)
        {
            var ctx     = new ClientContext(SharePointHelper.Url);
            var type    = new T();
            var results = new List <T>();

            try
            {
                var web  = SharePointHelper.GetWeb(ctx);
                var list = SharePointHelper.GetList(ctx, web, type.ListName);

                var caml  = SharePointHelper.GetByCaml(key, value, notEqual);
                var items = list.GetItems(caml);
                ctx.Load(items);
                ctx.ExecuteQuery();

                foreach (ListItem item in items)
                {
                    var t = new T();

                    t.MapFromList(item);
                    results.Add(t);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get " + type.ListName + ". " + ex.Message);
            }

            return(results);
        }
コード例 #3
0
ファイル: SPListBase.cs プロジェクト: jpavlov/OGE-450
        public static T GetBy(string key, int value)
        {
            var ctx = new ClientContext(SharePointHelper.Url);
            var t   = new T();

            try
            {
                var web  = SharePointHelper.GetWeb(ctx);
                var list = SharePointHelper.GetList(ctx, web, t.ListName);

                var caml  = SharePointHelper.GetByCaml(key, value);
                var items = list.GetItems(caml);
                ctx.Load(items);
                ctx.ExecuteQuery();

                var item = items.FirstOrDefault();

                t.MapFromList(item);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get " + t.ListName + ". " + ex.Message);
            }

            return(t);
        }
コード例 #4
0
        public static List <T> GetAllJoined(string joinList, string joinField, string[] projectedFields)
        {
            var ctx     = new ClientContext(SharePointHelper.Url);
            var type    = new T();
            var results = new List <T>();

            try
            {
                var web  = SharePointHelper.GetWeb(ctx);
                var list = SharePointHelper.GetList(ctx, web, type.ListName);

                var caml  = SharePointHelper.GetAllJoinCaml(joinList, joinField, projectedFields);
                var items = list.GetItems(caml);
                ctx.Load(items);
                ctx.ExecuteQuery();

                foreach (ListItem item in items)
                {
                    var t = new T();

                    t.MapFromList(item);

                    results.Add(t);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get " + type.ListName + ". " + ex.Message, ex);
            }

            return(results);
        }
コード例 #5
0
ファイル: SPListBase.cs プロジェクト: jpavlov/OGE-450
        public void Delete()
        {
            var ctx = new ClientContext(SharePointHelper.Url);

            T t = new T();

            try
            {
                var web  = SharePointHelper.GetWeb(ctx);
                var list = SharePointHelper.GetList(ctx, web, t.ListName);

                var item = list.GetItemById(Id);
                item.DeleteObject();
                ctx.ExecuteQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to delete " + t.ListName + " with id " + Id + ". " + ex.Message);
            }
        }
コード例 #6
0
ファイル: SPListBase.cs プロジェクト: jpavlov/OGE-450
        public static List <T> GetAllByView(string viewName)
        {
            var ctx     = new ClientContext(SharePointHelper.Url);
            var type    = new T();
            var results = new List <T>();

            try
            {
                var web  = SharePointHelper.GetWeb(ctx);
                var list = SharePointHelper.GetList(ctx, web, type.ListName);

                var view = list.Views.GetByTitle(viewName);
                ctx.Load(view);
                ctx.ExecuteQuery();

                var caml = new CamlQuery();
                caml.ViewXml = string.Format("<View><Query>{0}</Query></View>", view.ViewQuery);

                var items = list.GetItems(caml);
                ctx.Load(items);
                ctx.ExecuteQuery();

                foreach (ListItem item in items)
                {
                    var t = new T();

                    t.MapFromList(item);

                    results.Add(t);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get " + type.ListName + ". " + ex.Message);
            }

            return(results);
        }
コード例 #7
0
ファイル: SPListBase.cs プロジェクト: jpavlov/OGE-450
        public static T Get(int id)
        {
            var ctx = new ClientContext(SharePointHelper.Url);

            T t = new T();

            try
            {
                var web  = SharePointHelper.GetWeb(ctx);
                var list = SharePointHelper.GetList(ctx, web, t.ListName);

                var item = list.GetItemById(id);
                ctx.Load(item);
                ctx.ExecuteQuery();

                t.MapFromList(item, true);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get " + t.ListName + " with id " + id + ". " + ex.Message);
            }

            return(t);
        }