public ActionResult CreateImages(VenueImages vm, int Id, HttpPostedFileBase ImagePath) { string FullPath; string HashedData; if (ImagePath != null) { string extension = Path.GetExtension(ImagePath.FileName); HashedData = ComputeSha256Hash(ImagePath.FileName); FullPath = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(HashedData)) + extension; ImagePath.SaveAs(FullPath); FullPath = "~/Images/" + Path.GetFileName(HashedData) + extension; vm.VenuesId = Id; vm.ImagePath = FullPath; vm.ApplicationUserCreatedById = "4af95f1c-0f73-4df9-bb6d-166a07b6e5f4"; vm.ApplicationUserCreatedDate = DateTime.Now; vm.ApplicationUserLastUpdatedById = vm.ApplicationUserCreatedById; vm.ApplicationUserLastUpdatedDate = DateTime.Now; _context.VenueImages.Add(vm); _context.SaveChanges(); } return(RedirectToAction("CreateImages/" + Id)); }
public ActionResult DeleteImage(int id, VenueImages vm) { try { var venueImage = _context.VenueImages.Single(c => c.Id == vm.Id); var VenueId = _context.VenueImages.SingleOrDefault(v => v.Id == vm.Id).VenuesId; _context.VenueImages.Remove(venueImage); _context.SaveChanges(); return(RedirectToAction("CreateImages/" + VenueId)); } catch { return(View()); } }
public ActionResult EditImage(VenueImages vm, int Id, HttpPostedFileBase ImagePath) //Id = ImageId { string FullPath; string HashedData; var VenueId = _context.VenueImages.SingleOrDefault(v => v.Id == vm.Id).VenuesId; if (ImagePath != null) { string extension = Path.GetExtension(ImagePath.FileName); HashedData = ComputeSha256Hash(ImagePath.FileName); FullPath = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(HashedData)) + extension; ImagePath.SaveAs(FullPath); FullPath = "~/Images/" + Path.GetFileName(HashedData) + extension; vm.ApplicationUserLastUpdatedById = vm.ApplicationUserCreatedById; vm.ApplicationUserLastUpdatedDate = DateTime.Now; var imageinDb = _context.VenueImages.Single(v => v.Id == vm.Id); imageinDb.ImagePath = FullPath; _context.SaveChanges(); } return(RedirectToAction("CreateImages/" + VenueId)); }