示例#1
0
        public ResponseData <object> ChangeUserPower(int userId, [FromBody] UserPostData userPostData)
        {
            ResponseData <object> responseData;

            if (SessionHelper.IsExist(userPostData.Guid))
            {
                string adminAccount = HttpContext.Current.Session[userPostData.Guid].ToString();

                RoleTb admin = db.RoleTb.Where(u => u.isDel == false && u.account == adminAccount).FirstOrDefault();

                //判断是否为管理员
                if (admin != null && admin.powerNum == 99)
                {
                    RoleTb user = db.RoleTb.Where(u => u.isDel == false && u.roleId == userId).FirstOrDefault();

                    // 判断要操作的用户是否存在
                    if (user != null)
                    {
                        user.powerNum = userPostData.PowerNum;
                        try
                        {
                            db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                            if (db.SaveChanges() > 0)
                            {
                                responseData = ResponseHelper <object> .SendSuccessResponse();
                            }
                            else
                            {
                                responseData = ResponseHelper <object> .SendErrorResponse("修改失败");
                            }
                        }
                        catch (Exception ex)
                        {
                            responseData = ResponseHelper <object> .SendErrorResponse(ex.Message);
                        }
                    }
                    else
                    {
                        responseData = ResponseHelper <object> .SendErrorResponse("未找到该用户");
                    }
                }
                else
                {
                    responseData = ResponseHelper <object> .SendErrorResponse("用户登陆失效或权限不足", Models.StatusCode.OPERATION_ERROR);
                }
            }
            else
            {
                responseData = ResponseHelper <object> .SendErrorResponse("未登录", Models.StatusCode.OPERATION_ERROR);
            }

            return(responseData);
        }
示例#2
0
        public ResponseData <object> UpdateUserMessage(int userId, [FromBody] UserPostData userPostData)
        {
            ResponseData <object> responseData;

            if (SessionHelper.IsExist(userPostData.Guid))
            {
                RoleTb user = db.RoleTb.Where(u => u.isDel == false && u.roleId == userId).FirstOrDefault();

                if (user != null)
                {
                    user.nickName = userPostData.NickName ?? user.nickName;
                    user.pwd      = userPostData.Pwd ?? user.pwd;

                    try
                    {
                        db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                        if (db.SaveChanges() > 0)
                        {
                            responseData = ResponseHelper <object> .SendSuccessResponse();
                        }
                        else
                        {
                            responseData = ResponseHelper <object> .SendErrorResponse("修改失败");
                        }
                    }
                    catch (Exception ex)
                    {
                        responseData = ResponseHelper <object> .SendErrorResponse(ex.Message);
                    }
                }
                else
                {
                    responseData = ResponseHelper <object> .SendErrorResponse("未找到该用户");
                }
            }
            else
            {
                responseData = ResponseHelper <object> .SendErrorResponse("未登录", Models.StatusCode.OPERATION_ERROR);
            }

            return(responseData);
        }