Exemplo n.º 1
0
        public static List <T> GetAllBy(string key, string value, bool notEqual = false)
        {
            var ctx     = new ClientContext(SharePointHelper.MigrateUrl);
            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);
        }
Exemplo n.º 2
0
        public static List <OGEForm450> GetAllReviewable()
        {
            var ctx     = new ClientContext(SharePointHelper.Url);
            var type    = new OGEForm450();
            var results = new List <OGEForm450>();

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

                var caml  = GetReviewableCaml();
                var items = list.GetItems(caml);

                ctx.Load(items);
                ctx.ExecuteQuery();

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

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

            return(results);
        }
Exemplo n.º 3
0
        public virtual T Save()
        {
            ListItem newItem;

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

                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));
        }
Exemplo n.º 4
0
        public static List <ExtensionRequest> GetPendingExtensions(int ogeForm450Id)
        {
            var ctx     = new ClientContext(SharePointHelper.Url);
            var type    = new ExtensionRequest();
            var results = new List <ExtensionRequest>();

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

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

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

                    t.MapFromList(item);

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

            return(results);
        }
Exemplo n.º 5
0
        public static T GetBy(string key, int value)
        {
            var ctx = new ClientContext(SharePointHelper.MigrateUrl);
            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);
        }
Exemplo n.º 6
0
        private static string GetGroupEmails(string groupName)
        {
            using (ClientContext ctx = new ClientContext(SharePointHelper.Url))
            {
                var web = SharePointHelper.GetWeb(ctx);

                var group = SharePointHelper.GetGroup(ctx, web, groupName);
                var users = group.Users;

                ctx.Load(users);
                ctx.ExecuteQuery();

                var emails = "";

                foreach (User u in group.Users)
                {
                    if (!string.IsNullOrEmpty(u.Email))
                    {
                        emails += u.Email + ",";
                    }
                }


                emails = emails.TrimEnd(',');

                return(emails);
            }
        }
Exemplo n.º 7
0
        public static UserCollection GetUsersInGroup(string groupName)
        {
            using (ClientContext ctx = new ClientContext(SharePointHelper.Url))
            {
                var web = SharePointHelper.GetWeb(ctx);

                var group = SharePointHelper.GetGroup(ctx, web, groupName);
                var users = group.Users;

                ctx.Load(users);
                ctx.ExecuteQuery();

                return(users);
            }
        }
Exemplo n.º 8
0
        public bool Create()
        {
            bool returnVal = false;

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

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

                Folder folder = GetFolderIfExists(list, AttachmentGuid.ToString());

                if (folder == null)
                {
                    folder = CreateFolder(list, AttachmentGuid.ToString());
                }

                FileCreationInformation fci = new FileCreationInformation();

                fci.ContentStream = new MemoryStream(Content);
                fci.Url           = FileName;
                fci.Overwrite     = true;

                Microsoft.SharePoint.Client.File fileToUpload = folder.Files.Add(fci);

                MapToList(fileToUpload.ListItemAllFields);
                fileToUpload.ListItemAllFields.Update();

                SPContext.Load(fileToUpload);
                SPContext.Load(fileToUpload.ListItemAllFields);

                SPContext.ExecuteQuery();

                returnVal = true;
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to save " + ListName + " with id " + Id + ". " + ex.Message);
            }

            return(returnVal);
        }
Exemplo n.º 9
0
        public void Delete()
        {
            var ctx = new ClientContext(SharePointHelper.MigrateUrl);

            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);
            }
        }
Exemplo n.º 10
0
        new public static EthicsForm Get(int id)
        {
            var ctx = new ClientContext(SharePointHelper.Url);

            EthicsForm t = new EthicsForm();

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

                var item = list.GetItemById(id);

                ctx.Load(item);
                ctx.Load(item.File);
                ctx.ExecuteQuery();

                t.MapFromList(item, true);

                using (var memory = new MemoryStream())
                {
                    var data = item.File.OpenBinaryStream();
                    ctx.Load(item.File);
                    ctx.ExecuteQuery();

                    data.Value.CopyTo(memory);
                    t.FileName = item.File.Name;
                    t.Content  = memory.ToArray();
                }

                //var byteCount = fileInformation.Stream.Read(t.Content, 0, t.Size);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get " + t.ListName + " with id " + id + ". " + ex.Message);
            }

            return(t);
        }
Exemplo n.º 11
0
        public static List <T> GetAllByView(string viewName)
        {
            var ctx     = new ClientContext(SharePointHelper.MigrateUrl);
            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);
        }
Exemplo n.º 12
0
        public static T Get(int id)
        {
            var ctx = new ClientContext(SharePointHelper.MigrateUrl);

            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);
        }