Example #1
0
        public ActionResult AddNewBlogPost(AddBlogPostVM newPost)
        {
            if (ModelState.IsValid)
            {

                newPost.BlogPost.User.UserName = User.Identity.GetUserName();
                newPost.BlogPost.TimeCreated = DateTime.Now;
                newPost.BlogPost.Status = PageStatus.Pending;

                if (User.IsInRole("Admin"))
                {
                    newPost.BlogPost.Status = PageStatus.Approved;
                }

                foreach (var ht in newPost.hashtags)
                {
                    var newTag = new Hashtag();
                    newTag.HashtagTitle = ht;
                    newPost.BlogPost.Hashtags.Add(newTag);
                }

                var post = _ops.AddNewBlogPost(newPost.BlogPost).BlogPost;

                return View("BlogPostDetails", post);

                //Ajax API call for confirmation modal
            }

            newPost.InitializeCategoriesList(_ops.GetAllCategories().Categories);

            return View(newPost);
        }
Example #2
0
 public Response()
 {
     Users       = new List <ApplicationUser>();
     IdUserRoles = new List <IdentityUserRole>();
     IdRoles     = new List <IdentityRole>();
     Hashtag     = new Hashtag();
     Hashtags    = new List <Hashtag>();
     BlogPost    = new BlogPost();
     BlogPosts   = new List <BlogPost>();
     StaticPage  = new StaticPage();
     StaticPages = new List <StaticPage>();
     Category    = new Category();
     Categories  = new List <Category>();
     User        = new ApplicationUser();
     BlogStats   = new BlogStats();
 }
Example #3
0
 public Response()
 {
     Users = new List<ApplicationUser>();
     IdUserRoles = new List<IdentityUserRole>();
     IdRoles = new List<IdentityRole>();
     Hashtag = new Hashtag();
     Hashtags = new List<Hashtag>();
     BlogPost = new BlogPost();
     BlogPosts = new List<BlogPost>();
     StaticPage = new StaticPage();
     StaticPages = new List<StaticPage>();
     Category = new Category();
     Categories = new List<Category>();
     User = new ApplicationUser();
     BlogStats = new BlogStats();
 }
Example #4
0
        private Hashtag PopulateHashtagsFromReader(SqlDataReader dr)
        {
            Hashtag hashtag = new Hashtag();

            hashtag.HashtagId = (int)dr["HashtagID"];
            hashtag.HashtagTitle = dr["HashtagTitle"].ToString();
            hashtag.HashtagCount = int.Parse(dr["NumHts"].ToString());

            return hashtag;
        }
Example #5
0
        public Hashtag GetHashtagById(int hashtagId)
        {
            Hashtag hashtag = new Hashtag();

            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("@HashtagID", hashtagId);

                hashtag = cn.Query<Hashtag>("GetHashtagByID", p, commandType: CommandType.StoredProcedure).FirstOrDefault();
            }

            return hashtag;
        }
Example #6
0
        public ActionResult EditBlogPost(AddBlogPostVM vm)
        {
            if (ModelState.IsValid)
            {
                foreach (var ht in vm.hashtags)
                {
                    var newTag = new Hashtag();
                    newTag.HashtagTitle = ht;
                    vm.BlogPost.Hashtags.Add(newTag);
                }

                var oldHashtags = _jss.Serialize(_ops.GetHashtagsByBlogPostId(vm.BlogPost.BlogPostId).Hashtags.OrderBy(h => h.HashtagTitle).Select(h => h.HashtagTitle));

                var newHashtags = _jss.Serialize(vm.BlogPost.Hashtags.OrderBy(h => h.HashtagTitle).Select(h => h.HashtagTitle));

                if (oldHashtags != newHashtags)
                {
                    vm.BlogPost.HashtagsUpdated = true;
                }

                var blogPost = _ops.EditBlogPost(vm.BlogPost).BlogPost;

                return View("BlogPostDetails", blogPost);

            }

            vm.InitializeCategoriesList(_ops.GetAllCategories().Categories);

            return View(vm);
        }