public static dongdongdongEntities CreateDbContext() { dongdongdongEntities dbContext = (dongdongdongEntities)CallContext.GetData("dbContext"); if (dbContext == null) { dbContext = new dongdongdongEntities(); CallContext.SetData("dbContext", dbContext); } return(dbContext); }
public ActionResult UpVideo(HttpPostedFileBase file) { dongdongdongEntities db = new dongdongdongEntities(); if (file != null && file.ContentLength > 0) { string folderpath = "/Video/";//上传图片的文件夹 if (!Directory.Exists(folderpath)) { Directory.CreateDirectory(Server.MapPath(folderpath)); } string ext1 = Path.GetExtension(file.FileName); if (ext1 != ".mp4" && ext1 != ".rmvb" && ext1 != ".avi" && ext1 != ".flv")//笔者这儿修改了后缀的判断 { return(Json(new { statu = 201, msg = "文件格式不正确!" })); } else { string folder = Server.MapPath(folderpath); string name = DateTime.Now.ToString("yyyyMMddHHmmssff"); string ext = Path.GetExtension(file.FileName); string downpath = name + ext; string filepath = Server.MapPath(folderpath) + name + ext; Video_detail vd = new Video_detail(); vd.Video_address = folderpath + downpath; vd.Video_detail_name = "惊奇队长"; vd.Video_num = 1; vd.Video_id = 17; db.Video_detail.Add(vd); db.SaveChanges(); file.SaveAs(Path.Combine(folder, downpath)); return(Json(new { status = 200, src = downpath, id = name })); } } else { return(Json(new { status = 202, msg = "请上传文件!" })); } }