protected override void Seed(Models.MyModel context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }
public ActionResult Create(Models.MyModel Image, HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(Image)); } if (file == null) { //lägger till en error om bilder inte finns ModelState.AddModelError("Error ", "Missing Picture"); return(View(Image)); } Image.date = DateTime.Now; //Sparar på en specifik lication file.SaveAs(Path.Combine(Server.MapPath("~/Pictures"), file.FileName)); db.Add(new MyModel { ID = Guid.NewGuid(), ImgName = file.FileName }); return(View()); }