public async Task <ActionResult> Create(Paste newPaste) { try { var client = PastehubHttpClient.GetClient(); newPaste.UserId = User.Identity.GetUserId(); newPaste.CreatedDateTime = DateTime.Now; var serializedItem = JsonConvert.SerializeObject(newPaste); var response = await client.PostAsync("/api/pastes", new StringContent(serializedItem, Encoding.Unicode, "application/json")); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Home")); } else { return(Content("Error")); } } catch (Exception exception) { return(Content(exception.Message)); } }
public async Task <ActionResult> Delete(int id) { try { var client = PastehubHttpClient.GetClient(); var uri = new Uri(client.BaseAddress + "api/pastes/" + id); var response = await client.DeleteAsync(uri); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Home")); } else { return(Content("Error")); } } catch (Exception exception) { return(Content(exception.Message)); } }