public ActionResult Create(FormCollection collection, HttpPostedFileBase fileUpload) { try { using (var context = new SiteContainer()) { var banner = new Banner(); TryUpdateModel(banner, new[] { "Description", "Link", "Price" }); if (fileUpload != null) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); fileUpload.SaveAs(filePath); banner.ImageSource = fileName; } context.AddToBanner(banner); context.SaveChanges(); return RedirectToAction("Index"); } } catch { return View(); } }
/// <summary> /// Create a new Banner object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="imageSource">Initial value of the ImageSource property.</param> public static Banner CreateBanner(global::System.Int32 id, global::System.String imageSource) { Banner banner = new Banner(); banner.Id = id; banner.ImageSource = imageSource; return banner; }
/// <summary> /// Deprecated Method for adding a new object to the Banner EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBanner(Banner banner) { base.AddObject("Banner", banner); }