Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
        public async Task <IActionResult> GetList()
        {
            var currentUser = HttpContext.User;
            //var jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6InRlc3QxIiwicm9sZSI6InRlc3QxIiwibmJmIjoxNjA4MDE4MjE0LCJleHAiOjE2MDgwMTgyMjksImlhdCI6MTYwODAxODIxNH0.mSWppuNmp7Lhh5-qfySmOpZx-YK4taV6yOwu2qUv6dU";
            //var handler = new JwtSecurityTokenHandler();
            //var token = handler.ReadJwtToken(jwt);

            SharepointClientModel sharepointClientModel = new SharepointClientModel();

            sharepointClientModel = new SharepointClientModel()
            {
                ClientId     = "60891e37-f776-471f-80cf-59e74b0f9b93",
                ClientSecret = "Yf1MXgrwmv2dq1q0LEVg83kICWI3Da8ukD46g63kMCE=",
                GrantType    = "client_credentials",
                TenantID     = "9b048e01-f1bb-41c1-8279-71c212d0af1c",
                SiteName     = "sainglinhtoo.sharepoint.com",
                Resource     = "00000003-0000-0ff1-ce00-000000000000"
            };
            AccessTokenModel acc = new AccessTokenModel();

            acc = await SharePointHelper.GetToken(sharepointClientModel);

            var json = await SharePointHelper.GetList(acc.access_token);

            //var jsonData = JsonConvert.SerializeObject(json);
            var data = JObject.Parse(json);

            return(Ok(data));
            //return Unauthorized();
        }
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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);
        }