Ejemplo n.º 1
0
        public ActionResult Remove()
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            User user = Session["User"] as User;
            int? id   = Convert.ToInt32(Request.QueryString["id"]);

            if (id == null)
            {
                //弹窗同时后退一步
                return(Content("<script>alert('无效的用户请求');history.go(-1);</script>"));
            }
            noteDB.NoteBase.Remove(noteDB.NoteBase.FirstOrDefault(n => n.Id == id && n.UserID == user.Id));
            noteDB.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public ActionResult Remove()
        {
            if (HttpContext.Session.Get <User>("User") == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            User user = HttpContext.Session.Get <User>("User");
            int? id   = Convert.ToInt32(Request.Query["id"]);

            if (id == null)
            {
                //弹窗同时后退一步
                return(Content("<script>alert('无效的用户请求');history.go(-1);</script>"));
            }
            //noteDB.NoteBase.Remove(noteDB.NoteBase.FirstOrDefault(n => n.Id == id && n.UserID == user.Id));
            noteDB.NoteBase.FirstOrDefault(n => n.Id == id && n.UserID == user.Id).Deleted = true;
            noteDB.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
        public ActionResult Register(User user)
        {
            var item = noteDB.UserBase.FirstOrDefault <User>(m => m.UserName == user.UserName);

            if (item != null)
            {
                ModelState.AddModelError("", "用户名已经存在,无法注册。");
                return(View(user));
            }
            else
            {
                noteDB.UserBase.Add(user);
                noteDB.SaveChanges();
                return(RedirectToAction("Login", "Account"));
            }
        }