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)); }
public ActionResult DeleteConfirmed(int id) { Bandner bandner = db.Bandners.Find(id); db.Bandners.Remove(bandner); db.SaveChanges(); return(RedirectToAction("Index")); }
// 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)); }