コード例 #1
0
        public ActionResult Create([Bind(Include = "ID,Image,Link,CreatedDate,CreatedBy,Status")] Bandner bandner, HttpPostedFileBase img)
        {
            var path     = "";
            var filename = "";

            if (ModelState.IsValid)
            {
                if (img != null)
                {
                    //filename = Guid.NewGuid().ToString() + img.FileName;
                    filename = img.FileName;
                    path     = Path.Combine(Server.MapPath("/Content/upload/baner"), filename);
                    img.SaveAs(path);
                    bandner.Image = filename; //Lưu ý
                }
                else
                {
                    bandner.Image = "logo_l.png";
                }
                bandner.CreatedDate = Convert.ToDateTime(DateTime.Now.ToString());
                db.Bandners.Add(bandner);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bandner));
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Bandner bandner = db.Bandners.Find(id);

            db.Bandners.Remove(bandner);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        // GET: admin/Bandners/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Bandner bandner = db.Bandners.Find(id);

            if (bandner == null)
            {
                return(HttpNotFound());
            }
            return(View(bandner));
        }