Пример #1
0
        public ActionResult Create(HttpPostedFileBase file, tbl_Content _Content)
        {
            try
            {

                tbl_Content _tbl_Content = new tbl_Content();
                _tbl_Content.title = _Content.title;
                _tbl_Content.Description = Server.HtmlDecode(_Content.Description);
                _tbl_Content.status = 1;
                if(file!=null)
                {
                    pic = Path.GetFileName(file.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/images1/"), pic);
                    file.SaveAs(path);
                }
                _tbl_Content.imge = pic;
                _tbl_Content.MenuId = _Content.MenuId;
                db.tbl_Content.Add(_tbl_Content);
                db.SaveChanges();
                return View("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #2
0
        public ActionResult Edit(HttpPostedFileBase file, tbl_Content _Content, int? id)
        {
            try
            {
                tbl_Content _content = db.tbl_Content.Where(x => x.contentid == id).FirstOrDefault();
                _content.title = _Content.title;
                _content.Description = Server.HtmlDecode(_Content.Description);
                _content.status = _Content.status;
                if (file != null)
                {
                    pic = Path.GetFileName(file.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/images1/"), pic);
                    file.SaveAs(path);
                    _content.imge = pic;
                }
                else
                { }

                _content.MenuId = _Content.MenuId;

                db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }