Ejemplo n.º 1
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="context"></param>
        public void AddUsersRequest(HttpContext context)
        {
            var response = new ResponseMessage();

            try
            {
                string userName = context.Request.Form["UserName"];
                string role     = context.Request.Form["Role"];

                var adminUser = new AdminUser();
                adminUser.SuId     = Guid.NewGuid().ToString();
                adminUser.Role     = 2;//新开账户不给予赋予权限
                adminUser.UserName = userName;
                adminUser.Pwd      = "123456";
                var add = _AdminUserService.Add(adminUser);
                if (add)
                {
                    response.code = 0;
                    response.msg  = "添加成功";
                    context.Response.Write(SerializeHelp.ToJson(response));
                    return;
                }
                response.code = 500;
                response.msg  = "添加失败";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
            catch (Exception e)
            {
                response.code = 500;
                response.msg  = "操作失败,请重试";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string    username = this.txtUserName.Text.Trim();
            string    realName = this.txtRealName.Text.Trim();
            string    pass     = this.txtPass.Text.Trim();
            string    md5Pass  = encrypt.EncryptMd5(pass);
            int       roleId   = Convert.ToInt32(this.ddlRole.SelectedValue);
            AdminUser item     = new AdminUser();

            item.username = username;
            item.realName = realName;
            item.password = pass;
            item.md5Pass  = md5Pass;
            item.roleId   = roleId;
            item.status   = 1;
            item.remark   = "";
            if (this.hidAdminId.Value != "")      //编辑
            {
                item.id = Convert.ToInt32(this.hidAdminId.Value);
                int num = AdminUserService.Update(item);
                if (num > 0)
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('更新成功!');location.href='manager.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('更新失败!');location.href='manager.aspx'", true);
                }
            }
            else
            {
                if (AdminUserService.Exists(item))
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('用户已经存在,请更换!');location.href='manager.aspx'", true);
                    return;
                }
                int num = AdminUserService.Add(item);
                if (num > 0)
                {
                    this.txtPass.Text      = "";
                    this.txtPassAgain.Text = "";
                    this.txtRealName.Text  = "";
                    this.txtUserName.Text  = "";

                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "alert('添加成功!');location.href='manager.aspx'", true);
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddUser(Admin_User entity)
        {
            var result = ResModelFactory.ResDefault();

            try
            {
                entity.Id             = Guid.NewGuid().ToString();
                entity.CreateDate     = DateTime.Now;
                entity.CreateUserID   = CurrentUser.Id;
                entity.CreateUserName = CurrentUser.UserName;
                entity.DeleteMark     = false;
                //entity.Sex = 1;
                //entity.Age = 23;
                AdminUserService service = new AdminUserService();
                service.Add(entity);
            }
            catch (Exception ex)
            {
                result = ResModelFactory.ResError(ex.Message);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="context"></param>
        public void AddAdminUserRequest(HttpContext context)
        {
            var response = new ResponseMessage();

            try
            {
                string userName = context.Request.Form["UserName"];
                //string userPwd = context.Request.Form["Pwd"];
                string userEmail = context.Request.Form["Role"];
                string suId      = context.Request.Form["SuId"];

                AdminUser userInfo = new AdminUser();
                userInfo.UserName = userName;
                userInfo.Pwd      = "123456"; //管理员默认密码
                userInfo.Role     = Convert.ToInt32(userEmail);
                userInfo.SuId     = suId;

                var add = _userInfoService.Add(userInfo);

                if (add)
                {
                    response.code = 0;
                    response.msg  = "添加成功";
                    context.Response.Write(SerializeHelp.ToJson(response));
                    return;
                }
                response.code = 500;
                response.msg  = "添加失败";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
            catch (Exception e)
            {
                response.code = 500;
                response.msg  = "操作失败,请重试";
                context.Response.Write(SerializeHelp.ToJson(response));
            }
        }