Пример #1
0
        public void AdvImg(string par1, string par2, string par3, HttpPostedFileBase upImg)
        {
            using (ApplicationDbContext dbm = new ApplicationDbContext())
            {
                string        uploadpath = "UploadFile/Picture/" + DateTime.Now.Date.ToString("yyyy-MM-dd") + "/";
                DirectoryInfo info       = new DirectoryInfo(base.Server.MapPath("~/Content/" + uploadpath));
                if (!info.Exists)
                {
                    info.Create();
                }
                string s = UploadPicture(upImg, uploadpath);

                //根据编号查询对象
                AdvImg f = new AdvImg();
                f.LinkName     = par1;
                f.ImageAddress = s;
                f.LinkUrl      = par2;
                f.SortId       = par3;
                dbm.AdvImgs.Add(f);
                dbm.SaveChanges();
                HttpContext.Response.Write(s);
                HttpContext.Response.End();
                //根据编号查询对象
                //FriendlyLink f = new FriendlyLink();
                //f.LinkName = par1;
                //f.LinkUrl = par2;
                //f.SortId = par3;
                //bool r = dbm.AddFriendlyLinks(f);
                //return r;
            }
        }
Пример #2
0
        public string DelAdvImg(int id)
        {
            ApplicationDbContext dbm = new ApplicationDbContext();
            AdvImg f = new AdvImg();

            f.Id = id;
            dbm.AdvImgs.Attach(f);
            dbm.AdvImgs.Remove(f);
            dbm.SaveChanges();
            return("删除成功");
        }
Пример #3
0
        public void UpdateAdvImg(int par4, string par1, string par2, string par3, HttpPostedFileBase upImg)
        {
            using (ApplicationDbContext dbm = new ApplicationDbContext())
            {
                string        uploadpath = "UploadFile/Picture/" + DateTime.Now.Date.ToString("yyyy-MM-dd") + "/";
                DirectoryInfo info       = new DirectoryInfo(base.Server.MapPath("~/Content/" + uploadpath));
                if (!info.Exists)
                {
                    info.Create();
                }
                string s = "";
                //根据编号查询对象
                AdvImg f = new AdvImg();
                f.Id           = par4;
                f.LinkName     = par1;
                f.ImageAddress = par2;

                f.SortId = par3;

                if (upImg != null)
                {
                    s         = UploadPicture(upImg, uploadpath);
                    f.LinkUrl = s;
                }
                else
                {
                    f.LinkUrl = par2;
                }
                dbm.AdvImgs.Attach(f);

                dbm.Entry(f).State = EntityState.Modified;

                dbm.SaveChanges();
                HttpContext.Response.Write(s);
                HttpContext.Response.End();
            }
        }