public ActionResult Create(Artist artist, IEnumerable <HttpPostedFileBase> files) { if (ModelState.IsValid) { int i = 1; foreach (var file in files) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder string newFileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName; var path = Path.Combine(Server.MapPath("~/Content/uploads"), "artist_" + newFileName); file.SaveAs(path); if (i == 1) { artist.BioImage = "/Content/uploads/artist_" + newFileName; } else { artist.HomePageImage = "/Content/uploads/artist_" + newFileName; } } i++; } artist.CreatedDate = DateTime.Now; db.Artists.Add(artist); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(artist)); }
public ActionResult Create(MenuItem menuitem) { if (ModelState.IsValid) { db.MenuItems.Add(menuitem); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(menuitem)); }
public ActionResult Create(SiteText sitetext) { if (ModelState.IsValid) { db.SiteText.Add(sitetext); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sitetext)); }
public ActionResult Create(EnterPage page, HttpPostedFileBase file) { if (ModelState.IsValid) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder string newFileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName; var path = Path.Combine(Server.MapPath("~/Content/uploads"), newFileName); file.SaveAs(path); page.Image = "/Content/uploads/" + newFileName; } db.EnterPage.Add(page); db.SaveChanges(); return(RedirectToAction("Index", "Admin")); } return(View(page)); }
public ActionResult Create(Image image, IEnumerable <HttpPostedFileBase> files) { if (ModelState.IsValid) { int i = 1; foreach (var file in files) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder string newFileName = DateTime.Now.ToFileTimeUtc().ToString() + "_" + fileName; var path = Path.Combine(Server.MapPath("~/Content/uploads"), newFileName); file.SaveAs(path); if (i == 1) { image.Thumb = "/Content/uploads/" + newFileName; } else { image.Normal = "/Content/uploads/" + newFileName; } } i++; } image.CreatedDate = DateTime.Now; db.Images.Add(image); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", image.ArtistId); return(View(image)); }