示例#1
0
        public ActionResult Upload(HttpPostedFileBase file, string description)
        {
            using (ContentSharingEntities1 DB = new ContentSharingEntities1())
            {
                var ID = (from a in DB.UserTable where a.EmailAddress == HttpContext.User.Identity.Name select a.Id).First();

                var allowedExtensions = new[] { ".jpg", ".gif", ".mp4", ".png" };

                var checkextension = Path.GetExtension(file.FileName).ToLower();

                bool extension = false;

                foreach (var item in allowedExtensions)
                {
                    if (item.Contains(checkextension))
                    {
                        extension = true;
                    }
                }


                if (extension)
                {
                    try
                    {
                        file.SaveAs(Server.MapPath("~/Images/" + file.FileName));
                        string Route = "/Images/" + file.FileName;

                        ImgDB r = new ImgDB();

                        r.UserID      = ID;
                        r.Description = description;
                        r.Route       = Route;


                        ContentSharingEntities1 db = new ContentSharingEntities1();
                        db.ImgDB.Add(r);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }



            return(Redirect("/Account/Hot"));
        }
示例#2
0
        public MainWindow()
        {
            InitializeComponent();

            //EF codefirst 实体数据模型,可以快速建立数据库,数据库操作简单,但是效率较低
            ImgDB db = new ImgDB();

            db.ImgTables.Where(p => p.UserName == "jiaohongbo").ToList().ForEach(p => p.ImgTitle = "new_video_title");
            //db.ImgInfoes.RemoveRange(db.ImgInfoes.Where(p => p.UserName == "jiaohongbo"));
            db.SaveChanges();
            var nlist = db.ImgTables.ToList();

            nlist.ForEach(p => Console.WriteLine(p.UserName + " " + p.ImgTitle + " " + p.ImgContent + " " + p.ImgPath));


            //自定义数据库操作,效率较高
            //int re = DbHelperSQL.ExecuteSql("INSERT INTO ImgInfoes(UserName, Auditing, Flower,MonthSum,PlaySum,Tile,VideoContent,VideoPath,VideoTitle,VideoType,VideoDate) VALUES('jiaohongbo22222', 1, 12,12,12,12,'wefuewi1','###','video','film','" + DateTime.Now + "')");
            //string sqlstr = "select * from ImgInfoes";
            //DataSet data = DbHelperSQL.Query(sqlstr);
            //var list = IListDataSet.DataSetToIList<ImgInfo>(data, 0);
            //list.ToList().ForEach(p => Console.WriteLine(p.UserName + " " + p.VideoTitle + " " + p.VideoContent + " " + p.VideoType));

            //可以使用EF框架去建立数据库,然后自定义数据库操作进行增删改查,综合效率较高
        }