コード例 #1
0
        public ActionResult Insertnews()
        {
            //    Speru s = new Speru();
            sperunew s = new sperunew();

            s.heading     = Request["heading"];
            s.description = Request["description"];
            String img = Request["image"];


            if (img != null && img.Length > 0)
            {
                s.image_url = img;
                //  }
            }
            else
            {
                HttpPostedFileBase file  = Request.Files["imageUpload"];
                string             fname = s.heading + ".jpg";
                string             path  = Path.Combine(Server.MapPath("~/images"), fname);

                s.image_url = "/images/" + fname;
                //if(file !=null){
                file.SaveAs(path);
            }
            s.date = Request["date"];
            se.sperunews.Add(s);
            se.SaveChanges();
            return(RedirectToAction("Shownews"));
        }
コード例 #2
0
        public ActionResult Deletenews()
        {
            sperunew sn = new sperunew();
            int      id = Int32.Parse(Request["id"]);

            sn = se.sperunews.FirstOrDefault(x => x.Id == id);
            if (sn != null)
            {
                se.sperunews.Remove(sn);
                se.SaveChanges();
                return(RedirectToAction("Shownews"));
            }
            else
            {
                return(RedirectToAction("Shownews"));
            }
        }