public ActionResult Create(VideoUploadViewModel video) { if (ModelState.IsValid) { foreach (HttpPostedFileBase file in video.Files) { byte[] bytes; using (BinaryReader br = new BinaryReader(file.InputStream)) { bytes = br.ReadBytes(file.ContentLength); } Video v = new Video { name = video.name, location = video.location, data = bytes, contentType = file.ContentType }; if (video.catList.Count() > 0) { foreach (int catId in video.catList) { Cat c = db.Cats.Find(catId); Video_Cat_Junction catVideo = new Video_Cat_Junction { video_id = v.id, cat_id = catId }; db.Video_Cat_Junction.Add(catVideo); } } ; db.Videos.Add(v); db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(video)); }
public JsonResult VideoUpload(VideoUploadViewModel video) { if (ModelState.IsValid) { byte[] bytes; using (BinaryReader br = new BinaryReader(video.Files[0].InputStream)) { bytes = br.ReadBytes(video.Files[0].ContentLength); } Video v = new Video { name = video.name, location = video.location, data = bytes, contentType = video.Files[0].ContentType }; if (video.catList.Count() > 0) { foreach (int catId in video.catList) { Cat c = db.Cats.Find(catId); Video_Cat_Junction catVideo = new Video_Cat_Junction { video_id = v.id, cat_id = catId }; db.Video_Cat_Junction.Add(catVideo); } } ; db.Videos.Add(v); db.SaveChanges(); return(Json("success", JsonRequestBehavior.DenyGet)); } return(Json("failed", JsonRequestBehavior.DenyGet)); }