コード例 #1
0
        public HttpResponse newtag(string tag)
        {
            string        result  = "";
            BlogTagClient btc     = new BlogTagClient();
            BlogTag       blogTag = btc.GetByPartitionAndRowKey("blogTag", tag.ToLower());

            if (blogTag == null)
            {
                btc.AddNewItem(new BlogTag {
                    RowKey = tag.ToLower().Replace(" ", "-"), Tag = tag.ToLower(), PublicPosts = 0, TotalPosts = 0
                });
                result = "ok";
            }
            else
            {
                result = "exist";
            }
            Response.ContentType = "application/json";
            Response.Write("{\"result\": \"" + result + "\"}");
            Response.End();
            return(null);
        }
コード例 #2
0
        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());
        }