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