示例#1
0
        public ActionResult DeleteUser(int id)
        {
            ztest01Entities db = new ztest01Entities();
            var             ui = db.usersinfo.Where <usersinfo>(u => u.uid == id).FirstOrDefault();

            db.usersinfo.Remove(ui);

            if (db.SaveChanges() > 0)
            {
                return(RedirectToAction("UsersInfoView", "UsersInfo", new { id = 1 }));
            }
            else
            {
                return(Content("Error"));
            }
        }
示例#2
0
        [HttpPost]//只能接收post,优先处理post请求
        public ActionResult Register(usersinfo ui)
        {
            ui.udatetime = DateTime.Now.ToString();
            ztest01Entities db = new ztest01Entities();

            db.usersinfo.Add(ui);
            if (db.SaveChanges() > 0)
            {
                return(Content("成功"));
            }
            else
            {
                return(Content("失败"));
            }
            //return View();
        }
示例#3
0
        //如果表单元素的name属性的值和实体类中的属性的名字保持一致,
        //那么表单中的数据会自动赋值给实体中的属性
        //public ActionResult Regist()
        //{
        //[HttpPost]//优先处理post请求
        public ActionResult Regist(usersinfo ui)
        {
            //usersinfo ui = new usersinfo();
            //ui.uaccount = Request["username"];
            //ui.upassword = Request["userpass"];
            //ui.uemail = Request["useremail"];
            //ui.uphone = Request["userphone"];
            ui.udatetime = DateTime.Now.ToString();
            ztest01Entities db = new ztest01Entities();

            db.usersinfo.Add(ui);
            if (db.SaveChanges() > 0)
            {
                return(Content("成功"));
            }
            else
            {
                return(Content("失败"));
            }
        }
示例#4
0
        public ActionResult ExecuteUpdate(usersinfo ui)
        {
            ztest01Entities db     = new ztest01Entities();
            var             thisUi = db.usersinfo.Where(u => u.uid == ui.uid).FirstOrDefault();

            thisUi.uaccount  = ui.uaccount;
            thisUi.upassword = ui.upassword;
            thisUi.uemail    = ui.uemail;
            thisUi.uphone    = ui.uphone;
            thisUi.udatetime = DateTime.Now.ToString();
            db.usersinfo.Attach(thisUi);

            db.Entry(thisUi).State = EntityState.Modified;
            if (db.SaveChanges() > 0)
            {
                return(Content("修改成功"));
            }
            else
            {
                return(Content("失败"));
            }
        }