예제 #1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BlogSectionModel blogSection = _db.BlogSections.Find(id);

            if (blogSection == null)
            {
                return(HttpNotFound());
            }
            return(View(blogSection));
        }
예제 #2
0
        public ActionResult Edit(BlogSectionModel blogSection)
        {
            if (ModelState.IsValid)
            {
                var blg = _db.BlogSections.Find(blogSection.BlogSectionId);
                blg.SectionTitle   = blogSection.SectionTitle;
                blg.SectionContent = blogSection.SectionContent;

                //_db.Entry(blog).State = EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(blogSection));
        }
예제 #3
0
        public ActionResult Create(BlogSectionModel blogSection, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                System.IO.Directory.CreateDirectory(Server.MapPath("~/Images/Blog"));
                string path = "";
                if (file != null)
                {
                    string pic          = System.IO.Path.GetFileName(file.FileName);
                    string physicalPath =
                        System.IO.Path.Combine(Server.MapPath("~/Images/Blog"), pic);
                    path = "/Images/Blog/" + pic;
                    // file is uploaded
                    file.SaveAs(physicalPath);
                    blogSection.ImageUrl = path;
                }
                _db.BlogSections.Add(blogSection);
                _db.SaveChanges();
                //return RedirectToAction("Index");
            }

            return(RedirectToAction("Index"));
        }