示例#1
0
        //blog posts
        public void AddPost(Blog blogPost)
        {
            blogPost.Tags= GetHashtagIDs(blogPost.Tags);
            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand();
                cmd.CommandText = "AddNewPost";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Title", blogPost.Title);
                cmd.Parameters.AddWithValue("@BlogContent", blogPost.Content);
                cmd.Parameters.AddWithValue("@PostDate", blogPost.BlogDate);
                cmd.Parameters.AddWithValue("@Author", blogPost.Author);

                try
                {
                    cmd.Connection = cn;
                    cn.Open();
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            blogPost.BlogId = (int)dr["BlogId"];
                            break;
                        }
                    }
                Console.WriteLine("Record created successfully");
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }
            UpdateHashtagBlogTable(blogPost);
        }
        public void AddBlogPost(TinyMCEModelVM BlogPostData, string TagString, string authorName)
        {
            Blog blogPost = new Blog();
            blogPost.Tags = ConvertTagStringToList(TagString);
            blogPost.Title = BlogPostData.Title;
            blogPost.Author = authorName;
            blogPost.Content = BlogPostData.Content;
            blogPost.BlogDate = DateTime.Now;

            _repo.AddPost(blogPost);
        }
 public void UpdateHashtagBlogTable(Blog BlogToAdd)
 {
     throw new NotImplementedException();
     //this is for a cross table which does not exist in the fake repo
 }
        public void AddPost(Blog blogPost)
        {
            var blogList = GetAllBlogPosts();
            int blogIdCount = blogList.Max(x => x.BlogId);

            blogPost.BlogId = blogIdCount + 1;

            _blogPosts.Add(blogPost);
        }
示例#5
0
        private Blog PopulateBlogPostsFromDataReader(SqlDataReader dr)
        {
            Blog blogPost = new Blog();

            blogPost.BlogId = (int)dr["BlogId"];
            blogPost.Title = dr["Title"].ToString();
            blogPost.BlogDate = (DateTime)dr["PostDate"];
            //for (int i = 0; i < blogPost.Tags.Count(); i++)
            //{
            //    blogPost.Tags.ElementAt(i).TagId = (int)dr["TagId"];
            //} Need to populate a list of tags
            blogPost.Author = dr["Author"].ToString();
            blogPost.Content = dr["BlogContent"].ToString();
            blogPost.IsApproved = (bool)dr["IsApproved"];

            return blogPost;
        }
示例#6
0
        public void UpdateHashtagBlogTable(Blog BlogToAdd)
        {
            foreach (var item in BlogToAdd.Tags)
            {
                using (var cn = new SqlConnection(Settings.ConnectionString))
                {
                    var cmd = new SqlCommand();
                    cmd.CommandText = "UpdateBlogHashtagCrossTable";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@BlogId", BlogToAdd.BlogId);
                    cmd.Parameters.AddWithValue("@TagId", item.TagId);

                    try
                    {
                        cmd.Connection = cn;
                        cn.Open();
                        cmd.ExecuteNonQuery();
                        Console.WriteLine("Record created successfully");
                    }

                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }