public async Task <ActionResult> Delete(string id)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "LoginUI"));
            }
            long pwdID = 0;

            if (long.TryParse(id, out pwdID) == false)
            {
                return(Content("入参错误", "text/html"));
            }
            using (mlrmsEntities db = new mlrmsEntities())
            {
                sysadmin matchOne = db.sysadmin.Where(m => m.AdminID == pwdID).ToList().First();
                db.sysadmin.Attach(matchOne);
                db.Entry(matchOne).State = System.Data.Entity.EntityState.Deleted;
                await db.SaveChangesAsync();

                return(RedirectToAction("", "administrator"));
            }
        }
Beispiel #2
0
        public ActionResult Index()
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            using (mlrmsEntities db = new mlrmsEntities())
            {
                var userList = db.sysadmin.Where(m => m.AdminCode == name);
                if (userList == null || userList.Count() <= 0)
                {
                    return(Content("Not Found", "text/html"));
                }
                sysadmin item    = userList.First();
                Manager  manager = new Manager();
                manager.UserCode = item.AdminCode;
                manager.UserName = item.AdminName;
                manager.AdminId  = item.AdminID;
                return(View(manager));
            }
        }
Beispiel #3
0
        public async Task <ActionResult> Index(Manager info)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            try
            {
                if (ModelState.IsValid)
                {
                    using (mlrmsEntities db = new mlrmsEntities())
                    {
                        var userList = db.sysadmin.Where(m => m.AdminID == info.AdminId);
                        if (userList == null || userList.Count() <= 0)
                        {
                            return(Content("Not Found", "text/html"));
                        }
                        sysadmin item = userList.First();
                        string   pwd  = EncryptHelper.GetEncrypt(info.Passwd);
                        if (pwd != item.AdminPwd)   //如果密码验证不通过
                        {
                            ModelState.AddModelError("Passwd", "密码错误");
                            return(View());
                        }
                        item.AdminPwd = EncryptHelper.GetEncrypt(info.NewPwd);
                        db.sysadmin.Attach(item);
                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        await db.SaveChangesAsync();

                        ViewData["status"] = "true";
                        return(RedirectToAction("Logout", "LoginUI"));
                    }
                }
            }
            catch
            {
                ViewData["status"] = "false";
            }
            Manager manager = new Manager();

            manager.UserName = info.UserName;
            //系统登出
            return(View(manager));
        }
Beispiel #4
0
        public ActionResult Index(sysadmin user)
        {
            if (string.IsNullOrEmpty(user.AdminCode))
            {
                return(Content("false:用户名不能为空", "text/html"));
            }
            if (string.IsNullOrEmpty(user.AdminPwd))
            {
                return(Content("false:密码不能为空", "text/html"));
            }
            if (user.AdminCode.Length > 30)
            {
                return(Content("false:用户名长度不能超过30", "text/html"));
            }
            if (user.AdminPwd.Length > 32)
            {
                return(Content("false:密码长度不能超过32", "text/html"));
            }
            string encryptStr = EncryptHelper.GetEncrypt(user.AdminPwd);

            try
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    if (db.sysadmin.Where(m => (m.AdminCode == user.AdminCode) && (m.AdminPwd == encryptStr)).Count() > 0)
                    {
                        System.Text.Encoding enc         = System.Text.Encoding.GetEncoding("gb2312");
                        string encodeStr                 = HttpUtility.UrlEncode(user.AdminCode, enc);
                        System.Web.HttpCookie authCookie = new System.Web.HttpCookie("bemlogin", encodeStr);
                        authCookie.Expires = DateTime.Now.AddMinutes(30);
                        System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
                        //return RedirectToAction("Index", "Device");
                        return(Content("true:登录成功", "text/html"));
                    }
                    else
                    {
                        return(Content("false:用户名或密码错误", "text/html"));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("系统登录失败", ex);
                return(Content("false:数据库连接失败,请检查配置", "text/html"));
            }
        }
        public async Task <ActionResult> Create(NewAdmin info)
        {
            string name, error, loginName;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }
            try
            {
                using (mlrmsEntities db = new mlrmsEntities())
                {
                    var userList = db.sysadmin.Where(m => m.AdminCode == info.UserCode);

                    if (userList.Count() > 0)
                    {
                        ModelState.AddModelError("UserCode", "该管理员已存在");
                        return(View(info));
                    }
                    sysadmin item = new sysadmin();
                    item.AdminName  = info.UserName;
                    item.CreateDate = DateTime.Now;
                    item.AdminCode  = info.UserCode;
                    item.AdminType  = 1;
                    item.AdminPwd   = EncryptHelper.GetEncrypt("123456");
                    db.sysadmin.Add(item);

                    int result = await db.SaveChangesAsync();

                    return(RedirectToAction("", "administrator"));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("创建管理员失败", ex);
                ViewData["status"] = "false";
            }
            return(View(info));
        }