Ejemplo n.º 1
0
        public ActionResult EditBlogEntry(BlogViewModel vm)
        {
            var repo = RepositoryFactory.CreateRepository();
            var blog = new BlogEntry
            {
                Title       = vm.Title,
                Body        = vm.Body,
                IsApproved  = User.IsInRole("Admin"),
                User        = repo.GetUserbyAspId(User.Identity.GetUserId()),
                DatePosted  = vm.PostDate,
                DateUpdated = DateTime.Today
            };

            var tags = blops.ParseTags(vm.Body, vm.TagInput);

            foreach (var tag in tags)
            {
                blog.Tags.Add(new Tag {
                    Name = tag
                });
            }

            repo.EditBlogEntry(blog);
            return(RedirectToAction("ManageBlog", "Admin"));
        }
Ejemplo n.º 2
0
        public void ParseTagsTest()
        {
            var ops = new BlogPostOperations();

            string body = "This is a #test of how well my #METHOD parses #Tags.";

            string tagList = "here, Are more#tags # to# TEST #now";

            var result = ops.ParseTags(body, tagList);

            List <string> expected = new List <string> {
                "test", "METHOD", "Tags", "here", "Are", "more", "tags", "to", "TEST", "now"
            };

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 3
0
        public ActionResult AddBlogEntry(BlogViewModel vm /*, IEnumerable<HttpPostedFileBase> images*/)
        {
            var repo = RepositoryFactory.CreateRepository();
            var ops  = new BlogPostOperations();

            var blog = new BlogEntry()
            {
                Title      = vm.Title,
                Body       = vm.Body,
                DateExpire = vm.ExpireDate,
                //Images = new List<Image>(),
                User       = repo.GetUserbyAspId(User.Identity.GetUserId()),
                IsApproved = User.IsInRole("Admin")
            };

            #region Commented-out, multi-image upload method
            //TODO: MULTI-IMAGE, EVENTUALLY
            //foreach (var img in images)
            //{
            //    if (img != null && img.ContentLength > 0 && img.ContentType.Contains("image"))
            //    {
            //        try
            //        {
            //            string path = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName(img.FileName));
            //            img.SaveAs(path);
            //            blog.Images.Add(new Image {ImgPath = path});
            //        }
            //        catch (Exception ex)
            //        {
            //            ViewBag.Message = "ERROR:" + ex.Message.ToString();
            //        }
            //    }
            //}
            #endregion

            var tags = ops.ParseTags(vm.Body, vm.TagInput);
            foreach (var tag in tags)
            {
                blog.Tags.Add(new Tag {
                    Name = tag
                });
            }

            repo.AddBlogEntry(blog);

            return(RedirectToAction("Index", "Admin"));
        }