コード例 #1
0
        public async Task UpdatePlan(MyPlan myPlan)
        {
            var accessToken = await GetGraphAccessTokenAsync();

            var     restURL      = string.Format("{0}plans/{1}", SettingsHelper.GraphResourceUrl, myPlan.id);
            dynamic postPlanJSON = new JObject();

            postPlanJSON.title = myPlan.title;
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    byte[]         btBodys = Encoding.UTF8.GetBytes(postPlanJSON.ToString());
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(restURL);
                    request.Method      = "PATCH";
                    request.Accept      = "application/json";
                    request.ContentType = "application/json";
                    request.Headers.Add("Authorization", "Bearer " + accessToken);
                    request.Headers.Add("If-Match", myPlan.Etag);
                    request.GetRequestStream().Write(btBodys, 0, btBodys.Length);
                    using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
                    {
                        if (response.StatusCode == HttpStatusCode.NoContent)
                        {
                            //update successfully
                        }
                    }
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }
        }
コード例 #2
0
 public async Task UpdatePlan(MyPlan myPlan)
 {
     if (UseSDK)
     {
         await UpdatePlanSDK(myPlan);
     }
     else
     {
         await UpdatePlanREST(myPlan);
     }
 }
コード例 #3
0
 public async Task CreatePlan(MyPlan myPlan)
 {
     try
     {
         string groupId = await CreateGroup(myPlan.title);
         await CreatePlan(myPlan, groupId);
     }
     catch (Exception el)
     {
         el.ToString();
     }
 }
コード例 #4
0
        private async Task CreatePlanSDK(MyPlan myPlan, string groupId)
        {
            try
            {
                var graphServiceClient = await GetGraphServiceAsync();

                var planToCreate = new PlannerPlan
                {
                    Title = myPlan.title,
                    Owner = groupId
                };
                //reqPlan.Owner = myPlan.owner;

                await graphServiceClient.Planner.Plans.Request().AddAsync(planToCreate);
            }
            catch (Exception el)
            {
                el.ToString();
            }
        }
コード例 #5
0
        public async Task UpdatePlanSDK(MyPlan myPlan)
        {
            try
            {
                var graphServiceClient = await GetGraphServiceAsync();

                var reqPlan = await graphServiceClient.Planner.Plans[myPlan.id].Request().GetAsync();

                string etag = reqPlan.GetEtag();
                var    plan = new PlannerPlan
                {
                    Title = myPlan.title
                };
                //reqPlan.Owner = myPlan.owner;

                await graphServiceClient.Planner.Plans[reqPlan.Id].Request().Header("If-Match", etag).Header("Prefer", "return=representation").UpdateAsync(plan);
            }
            catch (Exception el)
            {
                el.ToString();
            }
        }
コード例 #6
0
        public async Task <MyPlan> GetPlanSDK(string id)
        {
            MyPlan plan = new MyPlan();
            var    graphServiceClient = await GetGraphServiceAsync();

            var reqPlan = await graphServiceClient.Planner.Plans[id].Request().GetAsync();

            try
            {
                if (reqPlan != null)
                {
                    plan.title = reqPlan.Title;
                    plan.Etag  = reqPlan.GetEtag();
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }

            return(plan);
        }
コード例 #7
0
        public async Task <MyPlan> GetPlan(string id)
        {
            MyPlan plan        = new MyPlan();
            var    accessToken = await GetGraphAccessTokenAsync();

            var restURL = string.Format("{0}plans/{1}", SettingsHelper.GraphResourceUrl, id);

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var accept = "application/json";

                    client.DefaultRequestHeaders.Add("Accept", accept);
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                    using (var response = await client.GetAsync(restURL))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var item = JObject.Parse(await response.Content.ReadAsStringAsync());

                            if (item != null)
                            {
                                plan.title = !string.IsNullOrEmpty(item["title"].ToString()) ? item["title"].ToString() : string.Empty;
                                plan.Etag  = !string.IsNullOrEmpty(item["@odata.etag"].ToString()) ? item["@odata.etag"].ToString() : "";
                            }
                        }
                    }
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }

            return(plan);
        }
コード例 #8
0
        private async Task CreatePlan(MyPlan myPlan, string groupId)
        {
            var accessToken = await GetGraphAccessTokenAsync();

            var     restURL      = string.Format("{0}plans/", SettingsHelper.GraphResourceUrl);
            dynamic postPlanJSON = new JObject();

            postPlanJSON.title = myPlan.title;
            postPlanJSON.owner = groupId;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                    var requestMessage = new HttpRequestMessage(HttpMethod.Post, restURL);
                    requestMessage.Content = new StringContent(postPlanJSON.ToString(), System.Text.Encoding.UTF8, "application/json");
                    using (var response = await client.SendAsync(requestMessage))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            return;
                        }
                        else
                        {
                            throw new Exception("add plan error: " + response.StatusCode);
                        }
                    }
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }
        }
コード例 #9
0
        public async Task<MyPlan> GetPlan(string id)
        {
            MyPlan plan = new MyPlan();
            var accessToken = await GetGraphAccessTokenAsync();
            var restURL = string.Format("{0}plans/{1}", SettingsHelper.GraphResourceUrl, id);
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var accept = "application/json";

                    client.DefaultRequestHeaders.Add("Accept", accept);
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                    using (var response = await client.GetAsync(restURL))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var item = JObject.Parse(await response.Content.ReadAsStringAsync());

                            if (item != null)
                            {
                                plan.title = !string.IsNullOrEmpty(item["title"].ToString()) ? item["title"].ToString() : string.Empty;
                                plan.Etag = !string.IsNullOrEmpty(item["@odata.etag"].ToString()) ? item["@odata.etag"].ToString() : "";
                            }
                        }
                    }
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }

            return plan;
        }
コード例 #10
0
 public async Task UpdatePlan(MyPlan myPlan)
 {
     var accessToken = await GetGraphAccessTokenAsync();
     var restURL = string.Format("{0}plans/{1}", SettingsHelper.GraphResourceUrl, myPlan.id);
     dynamic postPlanJSON = new JObject();
     postPlanJSON.title = myPlan.title;
     try
     {
         using (HttpClient client = new HttpClient())
         {
             byte[] btBodys = Encoding.UTF8.GetBytes(postPlanJSON.ToString());
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(restURL);
             request.Method = "PATCH";
             request.Accept = "application/json";
             request.ContentType = "application/json";
             request.Headers.Add("Authorization", "Bearer " + accessToken);
             request.Headers.Add("If-Match", myPlan.Etag);
             request.GetRequestStream().Write(btBodys, 0, btBodys.Length);
             using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
             {
                 if (response.StatusCode == HttpStatusCode.NoContent)
                 {
                     //update successfully
                 }
             }
         }
     }
     catch (Exception el)
     {
         el.ToString();
     }
 }
コード例 #11
0
        private async Task CreatePlan(MyPlan myPlan, string groupId)
        {
            var accessToken = await GetGraphAccessTokenAsync();
            var restURL = string.Format("{0}plans/", SettingsHelper.GraphResourceUrl);
            dynamic postPlanJSON = new JObject();
            postPlanJSON.title = myPlan.title;
            postPlanJSON.owner = groupId;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                    var requestMessage = new HttpRequestMessage(HttpMethod.Post, restURL);
                    requestMessage.Content = new StringContent(postPlanJSON.ToString(), System.Text.Encoding.UTF8, "application/json");
                    using (var response = await client.SendAsync(requestMessage))
                    {
                        if (response.IsSuccessStatusCode)
                            return;
                        else
                            throw new Exception("add plan error: " + response.StatusCode);
                    }
                }
            }
            catch (Exception el)
            {
                el.ToString();
            }
        }
コード例 #12
0
 public async Task CreatePlan(MyPlan myPlan)
 {
     try
     {
         string groupId = await CreateGroup(myPlan.title);
         await CreatePlan(myPlan, groupId);
     }
     catch (Exception el)
     {
         el.ToString();
     }
 }
コード例 #13
0
        public async Task<ActionResult> Update(MyPlan myPlan)
        {

            await _repo.UpdatePlan(myPlan);
            return Redirect("/Plan");
        }
コード例 #14
0
 public async Task<ActionResult> Create()
 {
     var myPlan = new MyPlan();
     return View(myPlan);
 }