public ActionResult Create(MusicItem model, HttpPostedFileBase fileUpload) { using (var context = new SiteContainer()) { var file = fileUpload; if (file != null) { var pi = new MusicItem(); string fileName = IOHelper.GetUniqueFileName("~/Content/Music/mp3", file.FileName); string filePath = Server.MapPath("~/Content/Music/mp3"); filePath = Path.Combine(filePath, fileName); file.SaveAs(filePath); pi.FileName = fileName; context.AddToMusicItem(pi); context.SaveChanges(); } return RedirectToAction("Index"); } }
/// <summary> /// Create a new MusicItem object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="fileName">Initial value of the FileName property.</param> public static MusicItem CreateMusicItem(global::System.Int32 id, global::System.String fileName) { MusicItem musicItem = new MusicItem(); musicItem.Id = id; musicItem.FileName = fileName; return musicItem; }
/// <summary> /// Deprecated Method for adding a new object to the MusicItem EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToMusicItem(MusicItem musicItem) { base.AddObject("MusicItem", musicItem); }