public ActionResult Create([Bind(Include = "PictureId,Content")] Picture picture, HttpPostedFileBase image) { if (image != null) { picture.Content = new byte[image.ContentLength]; image.InputStream.Read(picture.Content, 0, image.ContentLength); } db.Pictures.Add(picture); db.SaveChanges(); //if (ModelState.IsValid) //{ // db.Pictures.Add(picture); // db.SaveChanges(); // return RedirectToAction("Index"); //} return(View(picture)); }
public ActionResult Create(Picture pic, HttpPostedFileBase uploadImage) { if (ModelState.IsValid && uploadImage != null) { byte[] ImageData = null; // считал байты using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { ImageData = binaryReader.ReadBytes(uploadImage.ContentLength); } //установка массива файлов pic.Image = ImageData; db.Pictures.Add(pic); db.SaveChanges(); return(RedirectToAction("Pics")); } return(View(pic)); }
public static void Initialize(PictureContext context) { if (!context.Pictures.Any()) { context.Pictures.AddRange( new Picture { Name = "3.jpg", Likes = 0, Dislikes = 0, Grade = 0 }, new Picture { Name = "4.jpg", Likes = 0, Dislikes = 0, Grade = 0 } ); context.SaveChanges(); } }
public void PostPicture(Picture product) { db.Pictures.Add(product); db.SaveChanges(); }
public IActionResult ADD(Picture pic) { db.Pictures.Add(pic); db.SaveChanges(); return(RedirectToAction("Index")); }