public async Task <ActionResult> AddAsync(string name, DateTime date, string content) { var filename = string.Format( CultureInfo.InvariantCulture, "{0}.{1:yyyyMMdd}.md", name, date); using (var client = this.currentUser.GetAuthenticatedClient()) { if (client == null) { return(RedirectToAction("Profile", "Home")); } using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(content))) { var upload = await client.Files.UploadAsync("/" + filename, body : mem); var metadata = ArticleMetadata.Parse(upload.Name, upload.Rev); return(Redirect(string.Format( CultureInfo.InvariantCulture, "/Blogs/{0}/{1}", this.currentUser.BlogName, metadata.DisplayName))); } } }
public async Task <ActionResult> IndexAsync( string filename, string content, string rev) { using (var client = this.currentUser.GetAuthenticatedClient()) { if (client == null) { return(RedirectToAction("Profile", "Home")); } using (var mem = new MemoryStream(Encoding.UTF8.GetBytes(content))) { try { var updated = await client.Files.UploadAsync( "/" + filename, WriteMode.Overwrite.Instance, body : mem); rev = updated.Rev; } catch (ApiException <UploadError> e) { var uploadError = e.ErrorResponse.AsPath; if (uploadError != null) { var reason = uploadError.Value.Reason; var id = filename.Split('.')[0]; var message = string.Format("Unable to update {0}. Reason: {1}", id, reason); this.Flash(message, FlashLevel.Warning); return(RedirectToAction("Index", new { id = id })); } } } var metadata = ArticleMetadata.Parse(filename, rev); await client.GetArticle(this.currentUser.BlogName, metadata, bypassCache : true); this.Flash(string.Format( "Updated '{0}'.", metadata.Name)); return(Redirect(string.Format( "/Blogs/{0}/{1}", this.currentUser.BlogName, metadata.DisplayName))); } }