Ejemplo n.º 1
0
        public ActionResult Create(BlogPost blogpost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    //get the file name
                    string imageName = image.FileName;

                    //strip the extension from the file name
                    string ext = imageName.Substring(imageName.LastIndexOf("."));

                    //generate a guid for the new image name
                    string imageRename = Guid.NewGuid().ToString();

                    imageRename += ext;

                    //save the image to the productImages folder
                    image.SaveAs(Server.MapPath("~/Content/img/blogImages/" + imageRename));

                    //save the imageName to the Product Object
                    blogpost.BlogImageURL = imageRename;
                }
                if (image == null)
                {
                    blogpost.BlogImageURL = "noPhoto.jpg";
                }

                db.BlogPosts.AddObject(blogpost);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.BlogAuthorID = new SelectList(db.BlogAuthors, "AuthorID", "AuthorName", blogpost.BlogAuthorID);
            ViewBag.BlogStatusID = new SelectList(db.BlogPostStatus1, "PubStatusID", "BlogStatusName", blogpost.BlogStatusID);
            ViewBag.CategoryID = new SelectList(db.BlogCategories, "BlogCategoryID", "BlogCategoryName");
            return View(blogpost);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the BlogPosts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogPosts(BlogPost blogPost)
 {
     base.AddObject("BlogPosts", blogPost);
 }
Ejemplo n.º 3
0
        public ActionResult Edit(BlogPost blogpost, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {

                if (image != null)
                {
                    //get the file name
                    string imageName = image.FileName;

                    //strip the extension from the file name
                    string ext = imageName.Substring(imageName.LastIndexOf("."));

                    //generate a guid for the new image name
                    string imageRename = Guid.NewGuid().ToString();

                    imageRename += ext;

                    //save the image to the productImages folder
                    image.SaveAs(Server.MapPath("~/Content/img/blogImages/" + imageRename));

                    //save the imageName to the Product Object
                    blogpost.BlogImageURL = imageRename;
                }
                else
                {
                    blogpost.BlogImageURL = (from i in db.BlogPosts
                                               where i.BlogPostID == blogpost.BlogPostID
                                               select i.BlogImageURL).Single();
                }

                db.BlogPosts.Attach(blogpost);
                db.ObjectStateManager.ChangeObjectState(blogpost, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.BlogAuthorID = new SelectList(db.BlogAuthors, "AuthorID", "AuthorName", blogpost.BlogAuthorID);
            ViewBag.BlogStatusID = new SelectList(db.BlogPostStatus1, "PubStatusID", "BlogStatusName", blogpost.BlogStatusID);
            ViewBag.CategoryID = new SelectList(db.BlogCategories, "BlogCategoryID", "BlogCategoryName");
            return View(blogpost);
        }
 /// <summary>
 /// Create a new BlogPost object.
 /// </summary>
 /// <param name="blogPostID">Initial value of the BlogPostID property.</param>
 /// <param name="blogTitle">Initial value of the BlogTitle property.</param>
 /// <param name="blogArticle">Initial value of the BlogArticle property.</param>
 /// <param name="blogAuthorID">Initial value of the BlogAuthorID property.</param>
 /// <param name="blogStatusID">Initial value of the BlogStatusID property.</param>
 /// <param name="categoryID">Initial value of the CategoryID property.</param>
 public static BlogPost CreateBlogPost(global::System.Int32 blogPostID, global::System.String blogTitle, global::System.String blogArticle, global::System.Int32 blogAuthorID, global::System.Int32 blogStatusID, global::System.Int32 categoryID)
 {
     BlogPost blogPost = new BlogPost();
     blogPost.BlogPostID = blogPostID;
     blogPost.BlogTitle = blogTitle;
     blogPost.BlogArticle = blogArticle;
     blogPost.BlogAuthorID = blogAuthorID;
     blogPost.BlogStatusID = blogStatusID;
     blogPost.CategoryID = categoryID;
     return blogPost;
 }