public ActionResult AddImageToGallery(int galleryId, FormCollection form, HttpPostedFileBase fileUpload) { using (var context = new ContentStorage()) { var galleryItem = new Galleryitem(); TryUpdateModel(galleryItem, new[] { "SortOrder" }); string fileName = IOHelper.GetUniqueFileName("~/Content/Photos", fileUpload.FileName); string filePath = Server.MapPath("~/Content/Photos"); filePath = Path.Combine(filePath, fileName); fileUpload.SaveAs(filePath); galleryItem.ImageSource = fileName; var gallery = context.Gallery.Where(g => g.Id == galleryId).First(); gallery.GalleryItems.Add(galleryItem); context.SaveChanges(); return RedirectToAction("Details", "Gallery", new {Area = "", id = gallery.Name}); } }
/// <summary> /// Create a new Galleryitem object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="sortOrder">Initial value of the SortOrder property.</param> public static Galleryitem CreateGalleryitem(global::System.Int32 id, global::System.Int32 sortOrder) { Galleryitem galleryitem = new Galleryitem(); galleryitem.Id = id; galleryitem.SortOrder = sortOrder; return galleryitem; }
/// <summary> /// Deprecated Method for adding a new object to the Galleryitem EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToGalleryitem(Galleryitem galleryitem) { base.AddObject("Galleryitem", galleryitem); }