public ActionResult AjaxRemoveUserManage(string UserName)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             if (usr != null)
             {
                 usr.UserName = AllConsts.NULL_USER;
                 usr.LabourNum = int.Parse(AllConsts.NULL_USER);
                 usr.UnitNum = int.Parse(AllConsts.NULL_USER);
                 usr.pword = AllConsts.NULL_USER;
                 context.SaveChanges();
             }
             return Json("OK", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
 public ActionResult AjaxUserModify(
     string UserName,
     string RealName,
     string pword,
     int unitNum)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             if (usr != null)
             {
                 //usr.UserName = UserName;
                 usr.RealName = RealName;
                 usr.UnitNum = unitNum;
             }
             else
             {
                 UserProfile newusr = new UserProfile();
                 newusr.UserName = UserName;
                 newusr.RealName = RealName;
                 newusr.UnitNum = unitNum;
                 newusr.pword = pword;
                 context.UserProfiles.Add(newusr);
             }
             context.SaveChanges();
             return Json("OK", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
Example #3
0
        public ActionResult Manage(LocalPasswordModel model)
        {
            //if (Request.Cookies["User"] != null)
            //{
            //HttpCookie aCookie = Request.Cookies["User"];
            //ViewBag.RealName = Server.UrlDecode(aCookie["RealName"]);
            //int id = Convert.ToInt32(Server.UrlDecode(aCookie["ID"]));
            //int UnitNum = Convert.ToInt32(Server.UrlDecode(aCookie["UnitNum"]));
            //ViewBag.UnitName = Server.UrlDecode(aCookie["UnitName"]);

            ViewBag.Title = "首页";
            //ViewBag.UnitNum = UnitNum;
            ViewBag.ReturnUrl = Url.Action("Manage");

            if (ModelState.IsValid)
            {
                bool changePasswordSucceeded;
                try
                {
                    changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    using (MemberShipDataContext PracticeDC = new MemberShipDataContext())
                    {
                        UserProfile user = PracticeDC.UserProfiles.Where(u => u.UserName == @User.Identity.Name).FirstOrDefault();
                        if (null != user)
                        {
                            user.pword = model.NewPassword;
                            PracticeDC.SaveChanges();
                        }
                    }
                    return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
                }
                else
                {
                    ModelState.AddModelError("", "当前密码不正确或新密码无效。");
                }
            }
            return PartialView("~/Views/Admin/Manage.cshtml", model);
            //}
            //else
            //{
            //    WebSecurity.Logout();
            //    return RedirectToAction("Login", "Admin");
            //}
        }