Example #1
0
 public Comment(string Title, string Author, string AuthorSiteUrl, string CommentText, Post CurrentPost)
 {
     this.Author = Author;
     this.Title = Title;
     this.AuthorSiteUrl = AuthorSiteUrl;
     this.CommentText = CommentText;
     this.Post = CurrentPost;
     this.PostID = CurrentPost.ID;
 }
        public ActionResult Create(string title, string author, string siteurl, string content, HttpPostedFileBase uploadedImage, string uploadedVideo)
        {
            using (BlogDBContext context = new BlogDBContext())
            {
                byte[] image = null;
                MemoryStream target;

                if (uploadedImage != null)
                {
                    target = new MemoryStream();
                    uploadedImage.InputStream.CopyTo(target);
                    image = target.ToArray();
                }

                Post newPost = new Post(author, title, siteurl, content, image, uploadedVideo);
                context.Posts.Add(newPost);
                context.SaveChanges();
                return RedirectToAction("Index");
            }
        }
        public ActionResult Update(int id, string title, string author, string siteurl, string content, HttpPostedFileBase uploadedImage, string uploadedVideo)
        {
            using (BlogDBContext context = new BlogDBContext())
            {
                byte[] image = null;
                MemoryStream target;

                if (uploadedImage != null)
                {
                    target = new MemoryStream();
                    uploadedImage.InputStream.CopyTo(target);
                    image = target.ToArray();
                }

                Post newPost = new Post(author, title, siteurl, content, image, uploadedVideo);
                Post currPost = context.Posts.Where(u => u.ID == id).FirstOrDefault<Post>();
                currPost.Author = newPost.Author;
                currPost.Comments = newPost.Comments;
                currPost.Content = newPost.Content;
                currPost.Image = newPost.Image;
                currPost.PostDate = newPost.PostDate;
                currPost.SiteUrl = newPost.SiteUrl;
                currPost.Title = newPost.Title;
                currPost.Video = newPost.Video;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
        }