/// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task <GeneralResponse> RegistUser(RegistUserRequest request, ServerCallContext context)
        {
            if (!await db.Positions.AnyAsync(x => x.Id == request.PositionId))
            {
                return(ResponseHelper.BadResponse("指定的职位不存在"));
            }
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                return(ResponseHelper.BadResponse("用户名不能为空"));
            }
            if (await db.Users.AnyAsync(x => x.Name == request.Name))
            {
                return(ResponseHelper.BadResponse("用户名已存在"));
            }
            await db.Users.AddAsync(
                new User
            {
                Name       = request.Name,
                PositionId = request.PositionId,
                Password   = request.Password
            });

            int result = await db.SaveChangesAsync();

            if (result <= 0)
            {
                return(ResponseHelper.BadResponse());
            }
            return(new GeneralResponse
            {
                IsSuccess = true
            });
        }
Example #2
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <GeneralResponse> RegistUserAsync(UserRegistModel model)
        {
            RegistUserRequest user = new RegistUserRequest
            {
                Name       = model.Name,
                Password   = model.Password,
                PositionId = model.PositionId
            };
            GeneralResponse result = await userClient.RegistUserAsync(user);

            return(result);
        }