示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string name     = Request["name"];
                string phone    = Request["phone"];
                string address  = Request["address"];
                string eamil    = Request["eamil"];
                string time     = Request["time"];
                string classify = Request["classify"];
                var    file     = Request.Files[0];
                string path     = "/Admin/Img/" + Guid.NewGuid().ToString().ToLower() + ".jpg";
                file.SaveAs(Server.MapPath(path));

                PetServer pmodel = new PetServer()
                {
                    Name         = name,
                    Phone        = phone,
                    Address      = address,
                    Eamil        = eamil,
                    BusinessTime = time,
                    Classify     = classify,
                    ImgUrl       = path,
                    IsDelete     = false,
                    LocalX       = 10,
                    LocalY       = 20,
                };
                var db = MyContext.Create();
                db.PetServer.Add(pmodel); //添加
                db.SaveChanges();         //改变数据库
                //跳转页面
                Response.Redirect("/Admin/Page/ServerManager.aspx");
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = MyContext.Create();

            if (IsPostBack)
            {
                int UId = Convert.ToInt32(Request["UId"]);
                //查询
                PetServer model = db.PetServer.FirstOrDefault(p => p.ID == UId);
                //修改
                model.Name         = Request["name"];
                model.Phone        = Request["phone"];
                model.Address      = Request["address"];
                model.Eamil        = Request["eamil"];
                model.Classify     = Request["classify"];
                model.BusinessTime = Request["time"];

                if (!string.IsNullOrEmpty(Request.Files[0].FileName))
                {
                    //上传文件
                    var    file = Request.Files[0];
                    string path = "/Admin/Img/" + Guid.NewGuid().ToString().ToLower() + ".jpg";
                    file.SaveAs(Server.MapPath(path));
                    model.ImgUrl = path;
                }
                //修改
                db.Entry(model).State = System.Data.EntityState.Modified;
                //改变数据库
                db.SaveChanges();
                Response.Redirect("./ServerManager.aspx");
            }
            else
            {
                //用户编号ID
                int id = Convert.ToInt32(Request["id"]);


                umodel = db.PetServer.FirstOrDefault(u => u.ID == id);
            }
        }
示例#3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //接收id
            int       id    = Convert.ToInt32(context.Request["id"]);
            var       db    = MyContext.Create();
            PetServer model = db.PetServer.FirstOrDefault(u => u.ID == id);

            //删除
            db.Entry(model).State = System.Data.EntityState.Deleted;
            //改变数据库
            int r = db.SaveChanges();

            if (r > 0)
            {
                context.Response.Write("ok");
            }
            else
            {
                context.Response.Write("no");
            }
        }