public ActionResult AddImages(TripAddImageViewModel tripImages) { var test = Request.Files.Count; var test12 = Request.Files; if (tripImages.Images.Count() > 0) { var trip = this.trips.GetById(tripImages.TripID) .FirstOrDefault(); foreach (var uploadedFile in tripImages.Images) { if (uploadedFile != null && uploadedFile.ContentLength > 0) { Image image = null; using (var memory = new MemoryStream()) { uploadedFile.InputStream.CopyTo(memory); var content = memory.GetBuffer(); image = new Image { Content = content, FileExtension = uploadedFile.FileName.Split(new[] { '.' }).Last() }; trip.Images.Add(image); } } } this.trips.Update(trip); return(this.RedirectToAction("Details", new { id = trip.Id })); } return(null); }
public ActionResult AddImages(TripAddImageViewModel tripImages) { var test = Request.Files.Count; var test12 = Request.Files; if (tripImages.Images.Count() > 0) { var trip = this.trips.GetById(tripImages.TripID) .FirstOrDefault(); foreach (var uploadedFile in tripImages.Images) { if (uploadedFile != null && uploadedFile.ContentLength > 0) { Image image = null; using (var memory = new MemoryStream()) { uploadedFile.InputStream.CopyTo(memory); var content = memory.GetBuffer(); image = new Image { Content = content, FileExtension = uploadedFile.FileName.Split(new[] { '.' }).Last() }; trip.Images.Add(image); } } } this.trips.Update(trip); return this.RedirectToAction("Details", new { id = trip.Id }); } return null; }