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 NewArticle(HttpPostedFileBase headerImage, string headerCode, IEnumerable <HttpPostedFileBase> inputFile, IEnumerable <string> inputCode, string inputTitle, string category, string tags, string text, string articleDescription, string author, string makepublic) { if (AuthTokens == null || AuthTokens[3] != "su") { return(RedirectToAction("Index", "Home")); } headerCode = headerCode == null ? "" : headerCode; category = category == null ? "" : category; BlogCategoryClient bcc = new BlogCategoryClient(); BlogPostClient bpc = new BlogPostClient(); BlogTagClient btc = new BlogTagClient(); 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()); } string patt = @"yyyyMMdd"; string rowkey = DateTime.UtcNow.ToString(patt) + Regex.Replace(inputTitle.ToLower(), @"[^a-zA-z0-9]+", "-"); bpc.AddNewItem(new BlogPost { Author = author, Category = category.ToLower(), Title = inputTitle, HeaderImageCode = headerCode, Public = (makepublic != null), Removed = false, Date = DateTime.UtcNow, Article1 = article1, Article2 = article2, Article3 = article3, Article4 = article4, ArticleDescription = articleDescription, Tags = tags.ToLower(), RowKey = rowkey }); List <string> tagsList = tags.Split(',').ToList(); List <BlogTag> blogTags = new List <BlogTag>(); foreach (string tag in tagsList) { BlogTag blogTag = btc.GetByPartitionAndRowKey("blogTag", tag); if (blogTag != null) { blogTag.TotalPosts++; blogTag.PublicPosts++; btc.Update(blogTag); } else { btc.AddNewItem(new BlogTag { RowKey = tag, TotalPosts = 1, PublicPosts = 1 }); } } //BlogCategory categoryToUpdate = bcc.GetByPartitionAndRowKey("blogCategory", category.ToLower()); //categoryToUpdate.TotalPosts++; //bcc.Update(categoryToUpdate); PictureManager pm = new PictureManager(); if (headerImage != null && headerCode != "") { WebImage image = new WebImage(headerImage.InputStream); pm.UploadPictureToBlobStorage(image, headerCode.Substring(2, 4), "blog", rowkey, 960, 960, 50, 50, false, false); } 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(View()); }
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")); }