Example #1
0
        public ActionResult DeleteBlog(int id)
        {
            var repo = BlogRepoFactory.Create();

            repo.DeleteBlog(id);

            return(RedirectToAction("Index", "Home"));
        }
Example #2
0
        public ActionResult PendingPosts()
        {
            var repo = BlogRepoFactory.Create();

            var model = repo.GetUnpublishedBlogs();

            return(View(model));
        }
Example #3
0
        public ActionResult PublishBlog(int id)
        {
            var repo = BlogRepoFactory.Create();

            Blog blog = repo.GetBlogById(id);

            blog.IsFinished = true;

            repo.EditBlog(blog);

            return(RedirectToAction("PendingPosts"));
        }
Example #4
0
        // GET: Home
        public ActionResult Index()
        {
            var        repo  = BlogRepoFactory.Create();
            HomepageVM model = new HomepageVM();

            List <Blog> featuredBlogs = repo.GetFeaturedBlogs();
            List <Blog> allBlogs      = repo.GetAllBlogs();

            model.AllBlogs      = allBlogs;
            model.FeaturedBlogs = featuredBlogs;
            model.SetCategories(repo.getAllCategories());

            //repo.getBlogCategories(model.AllBlogs);
            //repo.getBlogCategories(model.FeaturedBlogs);


            return(View(model));
        }
Example #5
0
        public ActionResult AddBlog(BlogVM b)
        {
            var repo    = BlogRepoFactory.Create();
            var context = new ExploreMidwestDBContext();

            if (ModelState.IsValid)
            {
                Blog blog = new Blog();
                if (b.File != null)
                {
                    string pic  = Path.GetFileName(b.File.FileName);
                    string path = Path.Combine(
                        Server.MapPath("~/images"), pic);
                    // file is uploaded
                    b.File.SaveAs(path);

                    blog = new Blog
                    {
                        BlogId        = b.BlogId,
                        Body          = b.Body,
                        IsDeleted     = b.IsDeleted,
                        IsFinished    = b.IsFinished,
                        BlogTags      = new List <Tag>(),
                        Title         = b.Title,
                        Author        = User.Identity.Name,
                        Date          = DateTime.Now,
                        ImageLocation = "images/" + Path.GetFileName(b.File.FileName),
                    };
                }
                else
                {
                    blog = new Blog
                    {
                        BlogId     = b.BlogId,
                        Body       = b.Body,
                        IsDeleted  = b.IsDeleted,
                        IsFinished = b.IsFinished,
                        BlogTags   = new List <Tag>(),
                        Title      = b.Title,
                        Author     = User.Identity.Name,
                        Date       = DateTime.Now,
                    };
                }
                if (b.BlogCategory.CategoryId == 0)
                {
                    Category c = new Category
                    {
                        CategoryType = b.NewCategory
                    };
                    context.Category.Add(c);
                    context.SaveChanges();
                    blog.BlogCategory = context.Category.FirstOrDefault(g => g.CategoryType == c.CategoryType);
                }
                else
                {
                    blog.BlogCategory = context.Category.FirstOrDefault(c => c.CategoryId == b.BlogCategory.CategoryId);
                }
                repo.AddBlog(blog);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                b.SetCategories(context.Category.ToList());
                return(View(b));
            }
        }