public ActionResult DeleteConfirmed(int id) { MinLoLChampion minLoLChampion = db.MinLoLChampions.Find(id); db.MinLoLChampions.Remove(minLoLChampion); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Name,Title,ChampIcon,ChampPic,ChampBio,ChampID,UltimateID,ChampRoleID")] MinLoLChampion minLoLChampion, IEnumerable <HttpPostedFileBase> files) { if (ModelState.IsValid) { //empty strings string icon = ""; string background = ""; //get image file names foreach (var file in files) { if (file != null) { //use the name to get the extension string extcheck = file.FileName; string ext = extcheck.Substring(extcheck.LastIndexOf('.')); //black list malicious code if (ext == ".exe" || ext == ".dll") { //could set the photoUrl to null before returning //sends to the view before persisting to the structure return(View(minLoLChampion)); } if (ext == ".png") { icon = minLoLChampion.Name + ext; file.SaveAs(Server.MapPath("~/Content/Champions/Icons/" + icon)); } else if (ext == ".jpg") { background = minLoLChampion.Name + ext; file.SaveAs(Server.MapPath("~/Content/Champions/Pics/" + background)); } } } ////add img values to champ object minLoLChampion.ChampIcon = icon; minLoLChampion.ChampPic = background; db.MinLoLChampions.Add(minLoLChampion); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ChampRoleID = new SelectList(db.MinLoLRoles, "ChampRoleID", "RoleName", minLoLChampion.ChampRoleID); ViewBag.UltimateID = new SelectList(db.MinLoLUltimates, "UltimateID", "UltimateName", minLoLChampion.UltimateID); return(View(minLoLChampion)); }
// GET: MinLoLChampions/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MinLoLChampion minLoLChampion = db.MinLoLChampions.Find(id); if (minLoLChampion == null) { return(HttpNotFound()); } return(View(minLoLChampion)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MinLoLChampion minLoLChampion = db.MinLoLChampions.Find(id); string p1 = minLoLChampion.ChampIcon; string p2 = minLoLChampion.ChampPic; TempData["Icon"] = p1; TempData["Pic"] = p2; if (minLoLChampion == null) { return(HttpNotFound()); } ViewBag.ChampRoleID = new SelectList(db.MinLoLRoles, "ChampRoleID", "RoleName", minLoLChampion.ChampRoleID); ViewBag.UltimateID = new SelectList(db.MinLoLUltimates, "UltimateID", "UltimateName", minLoLChampion.UltimateID); return(View(minLoLChampion)); }