Esempio n. 1
0
        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" }
            });
        }
Esempio n. 2
0
 public ActionResult Post(string year, string month, string day, string title)
 {
     if (year != null && month != null && day != null && title != null)
     {
         BlogPostClient bpc    = new BlogPostClient();
         string         rowkey = year + month + day + title;
         BlogPost       post   = bpc.GetByPartitionAndRowKey("blogPost", rowkey.ToLower());
         if (post != null && post.Removed == false) // && post.Public == true && post.Removed == false)
         {
             ViewBag.PostTitle          = post.Title;
             ViewBag.HeaderImage        = post.HeaderImageCode;
             ViewBag.Category           = post.Category;
             post.Tags                  = post.Tags != null ? post.Tags : "";
             ViewBag.Tags               = post.Tags.Split(',');
             ViewBag.Path               = rowkey.ToLower();
             ViewBag.Url                = post.Date.ToString("yyyy/MM/dd/") + Regex.Replace(post.Title.ToLower(), @"[^a-zA-z0-9]+", "-");
             ViewBag.Date               = monthName(month) + " " + day + ", " + year;
             ViewBag.ArticleDescription = post.ArticleDescription;
             string text = post.Article1 + post.Article2 + post.Article3 + post.Article4;
             ViewBag.Article = text.Replace("\n", "").Replace("\r", "");
             return(View());
         }
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 3
0
        public ActionResult Edit(string id)
        {
            PictureManager pm = new PictureManager();

            if (AuthTokens == null || AuthTokens[3] != "su")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null || id == "")
            {
                return(RedirectToAction("Admin"));
            }
            BlogPostClient bpc    = new BlogPostClient();
            string         rowkey = id;
            BlogPost       post   = bpc.GetByPartitionAndRowKey("blogPost", rowkey);

            if (post != null) // && post.Public == true && post.Removed == false)
            {
                ViewBag.RowKey          = post.RowKey;
                ViewBag.PostTitle       = post.Title;
                ViewBag.Category        = post.Category;
                ViewBag.Path            = rowkey;
                ViewBag.Author          = post.Author;
                ViewBag.HeaderImageCode = post.HeaderImageCode;
                ViewBag.Tags            = post.Tags.Split(',');
                ViewBag.Url             = post.Date.ToString("yyyy/MM/dd/") + Regex.Replace(post.Title.ToLower(), @"[^a-zA-z0-9]+", "-");
                ViewBag.Date            = post.Date.ToString("MMMMMMMMM dd, yyyy");
                string text = post.Article1 + post.Article2 + post.Article3 + post.Article4;
                ViewBag.ArticleDescription = post.ArticleDescription;
                ViewBag.Article            = text.Replace("\n", "").Replace("\r", "");
                ViewBag.Images             = pm.ListBlobsSegmented("blog", rowkey).Select(x => x.Uri.Segments.Last()).Where(x => !x.Contains("_t") && x != post.HeaderImageCode.Substring(2, 4));
                return(View());
            }
            return(RedirectToAction("Admin"));
        }
Esempio n. 4
0
        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"));
        }