public ActionResult Create(FormCollection form, HttpPostedFileBase uploadFile) { using (var context = new ModelContainer()) { var category = new Category(); TryUpdateModel(category, new[] { "Title", "SortOrder" }); /* string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); uploadFile.SaveAs(filePath); category.ImageSource = fileName; */ context.AddToCategory(category); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { Area = "" }); }
/// <summary> /// Create a new Category object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="imageSource">Initial value of the ImageSource property.</param> public static Category CreateCategory(global::System.Int32 id, global::System.String title, global::System.String imageSource) { Category category = new Category(); category.Id = id; category.Title = title; category.ImageSource = imageSource; return category; }
/// <summary> /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCategory(Category category) { base.AddObject("Category", category); }