public JsonResult togglePost(string rowkey) { BlogPostClient bpc = new BlogPostClient(); BlogTagClient btc = new BlogTagClient(); BlogPost blogPost = bpc.GetByPartitionAndRowKey("blogPost", rowkey); if (blogPost != null) { blogPost.Removed = !blogPost.Removed; bpc.Update(blogPost); List <string> tags = new List <string>(blogPost.Tags.Split(',')); foreach (string tag in tags) { BlogTag blogTag = btc.GetByPartitionAndRowKey("blogTag", tag); if (blogTag != null) { if (blogPost.Removed) { blogTag.PublicPosts--; } else { blogTag.PublicPosts++; } btc.Update(blogTag); } } } return(new JsonResult { Data = new { result = "ok" } }); }
public ActionResult Edit(string inputTitle, string tags, string text, string rowkey, string articledescription, HttpPostedFileBase headerImage, IEnumerable <HttpPostedFileBase> inputFile, IEnumerable <string> inputCode) { if (AuthTokens == null || AuthTokens[3] != "su") { return(RedirectToAction("Index", "Home")); } BlogPostClient bpc = new BlogPostClient(); BlogTagClient btc = new BlogTagClient(); BlogPost blogPost = bpc.GetByPartitionAndRowKey("blogPost", rowkey); if (blogPost != null) { string article1 = ""; string article2 = ""; string article3 = ""; string article4 = ""; if (text.Length <= 32500) { article1 = text; } else if (text.Length > 32500 && text.Length <= 65000) { article1 = text.Substring(0, 32500); article2 = text.Substring(32500); } else if (text.Length > 65000 && text.Length <= 97500) { article1 = text.Substring(0, 32500); article2 = text.Substring(32500, 32500); article3 = text.Substring(65000); } else if (text.Length > 97500 && text.Length <= 130000) { article1 = text.Substring(0, 32500); article2 = text.Substring(32500, 32500); article3 = text.Substring(65000, 32500); article4 = text.Substring(97500); } else { ViewBag.Error = "Article too long"; return(View()); } blogPost.Article1 = article1; blogPost.Article2 = article2; blogPost.Article3 = article3; blogPost.Article4 = article4; blogPost.Title = inputTitle; blogPost.ArticleDescription = articledescription; List <string> currentTagList = blogPost.Tags.Split(',').ToList(); List <string> newTagList = tags.Split(',').ToList(); foreach (string tag in currentTagList) { if (!newTagList.Contains(tag)) { BlogTag blogTag = btc.GetByPartitionAndRowKey("blogTag", tag); if (blogTag != null) { blogTag.PublicPosts--; btc.Update(blogTag); } } } foreach (string tag in newTagList) { if (!currentTagList.Contains(tag)) { BlogTag blogTag = btc.GetByPartitionAndRowKey("blogTag", tag); if (blogTag != null) { blogTag.PublicPosts++; btc.Update(blogTag); } } } blogPost.Tags = tags.ToLower(); bpc.Update(blogPost); PictureManager pm = new PictureManager(); if (headerImage != null) { WebImage image = new WebImage(headerImage.InputStream); var b = pm.UploadPictureToBlobStorage(image, blogPost.HeaderImageCode.Substring(2, 4), "blog", rowkey, 960, 960, 50, 50, false, false); } if (inputFile != null) { List <HttpPostedFileBase> files = inputFile.ToList(); List <string> codes = inputCode.ToList(); for (var i = 0; i < files.Count; i++) { if (files[i] != null) { WebImage image = new WebImage(files[i].InputStream); pm.UploadPictureToBlobStorage(image, codes[i].Substring(2, 4), "blog", rowkey, 960, 960, 50, 50, false, false); } } } } return(RedirectToAction("Admin")); }