コード例 #1
0
ファイル: LinkManager.cs プロジェクト: saguiitay/CopyRestAPI
        public async Task <Link> CreateLink(LinkCreate newLink)
        {
            if (newLink == null)
            {
                throw new ArgumentNullException("newLink");
            }

            string serializeObject = JsonConvert.SerializeObject(newLink);

            using (var httpContent = new StringContent(serializeObject))
            {
                var httpRequestItem = CreateHttpRequestItem(Consts.Links, HttpMethod.Post, httpContent);

                using (var response = await HttpRequestHandler.ExecuteAsync(httpRequestItem).ConfigureAwait(false))
                {
                    var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        throw new ServerException((int)response.StatusCode, result);
                    }

                    return(JsonConvert.DeserializeObject <Link>(result));
                }
            }
        }
コード例 #2
0
        public ActionResult Create(LinkCreate link)
        {
            if (!ModelState.IsValid)
            {
                return(View(link));
            }

            ILinkDAC dac = new LinkDAC();

            dac.Add(link.URL, link.Title, link.Note, link.SortOrder);
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task<Link> CreateLink(LinkCreate newLink)
        {
            string url = string.Format("{0}/links", URL.RESTRoot);

            string serializeObject = JsonConvert.SerializeObject(newLink);

            HttpContent httpContent = new StringContent(serializeObject);

            HttpRequestItem httpRequestItem = CreateHttpRequestItem(url, HttpMethod.Post, httpContent);

            string executeAsync = await _httpRequestHandler.ReadAsStringAsync(httpRequestItem);

            return JsonConvert.DeserializeObject<Link>(executeAsync);
        }
コード例 #4
0
        public async Task <Link> CreateLink(LinkCreate newLink)
        {
            string url = string.Format("{0}/links", URL.RESTRoot);

            string serializeObject = JsonConvert.SerializeObject(newLink);

            HttpContent httpContent = new StringContent(serializeObject);

            HttpRequestItem httpRequestItem = CreateHttpRequestItem(url, HttpMethod.Post, httpContent);

            string executeAsync = await _httpRequestHandler.ReadAsStringAsync(httpRequestItem);

            return(JsonConvert.DeserializeObject <Link>(executeAsync));
        }