Ejemplo n.º 1
0
        public ActionResult Create(BlogPostCreationModel postModel)
        {
            BlogPost newPost = new BlogPost();

            if (ModelState.IsValid)
            {
                newPost.PostContent = postModel.PostContent;
                newPost.TitleOfPost = postModel.Title;
                newPost.UserId      = Convert.ToInt32(User.Identity.GetUserId());
                newPost.DateOfPost  = DateTime.Now;
            }

            byte[] fileData = null;

            int count = Request.Files.Count;

            if (Request.Files.Count != 0)
            {
                using (var binaryReader = new BinaryReader(Request.Files["photo"].InputStream))
                {
                    if (Request.Files["photo"].ContentLength != 0)
                    {
                        fileData = binaryReader.ReadBytes(Request.Files["photo"].ContentLength);
                        newPost.PictureContent = fileData;
                    }
                }
            }

            Repo.Save(newPost);
            Repo.Commit();


            return(RedirectToAction("Index"));
        }