Esempio n. 1
0
        public ActionResult news_edit(int id, FormCollection collection)
        {
            var data = (from r in db.and_news_tbl
                        where r.pk_news_id == id
                        select r).FirstOrDefault();


            data.news_title = collection["news_title"];
            HttpPostedFileBase hp = Request.Files["fileuploadDemo"];

            if (hp != null && hp.FileName != "")
            {
                string path = "~/Images/" + hp.FileName;
                if (data.news_image != path)
                {
                    if (data.news_image == "~/Blog_image/no_image.gif")
                    {
                        hp.SaveAs(Server.MapPath(path));
                    }
                    else
                    {
                        System.IO.File.Delete(Server.MapPath(data.news_image));
                        hp.SaveAs(Server.MapPath(path));
                    }
                }
                data.news_image = path;
            }
            data.news_desc     = collection["news_desc"];
            data.news_date     = Convert.ToDateTime(collection["news_date"]);
            data.news_isactive = collection["news_isactive"];
            news_admin _nt = new news_admin();

            _nt.news_title    = data.news_title;
            _nt.news_image    = data.news_image;
            _nt.news_desc     = data.news_desc;
            _nt.news_date     = data.news_date.ToString();
            _nt.news_isactive = data.news_isactive;

            db.SaveChanges();
            return(RedirectToAction("news_all_admin"));
        }
Esempio n. 2
0
        public ActionResult DeleteAll(FormCollection frm)
        {
            var chkvalue = frm.GetValues("assignChkBx");

            foreach (var id in chkvalue)
            {
                news_admin n_m  = new news_admin();
                int        id1  = Convert.ToInt32(id);
                var        data = (from c in db.and_event_tbl where c.pk_event_id == id1 select c).First();
                if (data.event_img != null || data.event_img != "")
                {
                    if (data.event_img != "~/Blog_image/no_image.gif")
                    {
                        System.IO.File.Delete(Server.MapPath(data.event_img));
                    }
                }

                db.and_event_tbl.Remove(data);
                db.SaveChanges();
            }
            return(RedirectToAction("events_all_admin", "Admin_events"));
        }