Exemplo n.º 1
0
        public async Task <BaseApiResponse> SetMyParent(SetMyParentRequest request)
        {
            request.CheckNotNull(nameof(request));

            TryInitUserModel();
            if (!request.Mobile.IsMobileNumber())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "请输入正确的手机号"
                });
            }
            var parent = _userQueryService.FindUser(request.Mobile);

            if (parent == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该推荐人"
                });
            }

            var command = new SetMyParentCommand(parent.Id)
            {
                AggregateRootId = _user.Id
            };

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Exemplo n.º 2
0
        public async Task <BaseApiResponse> SetParent(SetParentRequest request)
        {
            request.CheckNotNull(nameof(request));
            var user = _userQueryService.FindUser(request.Id);

            if (user == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该用户"
                });
            }

            if (!request.Mobile.IsMobileNumber())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "请输入正确的手机号"
                });
            }
            var parent = _userQueryService.FindUser(request.Mobile);

            if (parent == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该推荐人"
                });
            }

            if (user.CreatedOn < parent.CreatedOn)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "推荐人的注册日期似乎比该用户晚"
                });
            }

            var command = new SetMyParentCommand(parent.Id)
            {
                AggregateRootId = request.Id
            };

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }

            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(),
                         "设置用户的推荐人",
                         request.Id, "设置用户:{0}的推荐人为:{1}".FormatWith(user.Mobile, request.Mobile));
            return(new BaseApiResponse());
        }
Exemplo n.º 3
0
        public void Handle(ICommandContext context, SetMyParentCommand command)
        {
            User parent = null;

            if (command.ParentId != Guid.Empty)
            {
                parent = context.Get <User>(command.ParentId);
            }
            context.Get <User>(command.AggregateRootId).SetMyParent(parent);
        }
Exemplo n.º 4
0
        public async Task <BaseApiResponse> SetMyParent([FromBody] SetMyParentRequest request)
        {
            request.CheckNotNull(nameof(request));

            var currentAccount = _contextService.GetCurrentAccount(HttpContext);

            if (!request.Mobile.IsMobileNumber())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "请输入正确的手机号"
                });
            }
            var parent = _userQueryService.FindUser(request.Mobile);

            if (parent == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该推荐人"
                });
            }
            var user = _userQueryService.FindUser(currentAccount.UserId.ToGuid());

            if (user.CreatedOn < parent.CreatedOn)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "推荐人的注册日期似乎比您晚"
                });
            }

            var command = new SetMyParentCommand(parent.Id)
            {
                AggregateRootId = currentAccount.UserId.ToGuid()
            };

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Exemplo n.º 5
0
        public async Task <BaseApiResponse> Edit(EditRequest request)
        {
            request.CheckNotNull(nameof(request));
            var user = _userQueryService.FindUser(request.Id);

            if (user == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该用户"
                });
            }

            if (request.ParentMobile.IsMobileNumber())
            {
                //设置推荐人
                var parent = _userQueryService.FindUser(request.ParentMobile);
                if (parent == null)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "没找到该推荐人"
                    });
                }
                if (user.CreatedOn < parent.CreatedOn)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "推荐人的注册日期似乎比该用户晚"
                    });
                }
                var command = new SetMyParentCommand(parent.Id)
                {
                    AggregateRootId = request.Id
                };
                await ExecuteCommandAsync(command);
            }

            if (request.NickName.Length > 20)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "昵称长度不得超过20字符."
                });
            }
            if (!"男,女,保密".IsIncludeItem(request.Gender))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "性别参数错误,非: 男/女/保密"
                });
            }

            var command2 = new EditUserCommand(
                request.Id,
                request.NickName,
                request.Gender,
                request.Role);
            var result = await ExecuteCommandAsync(command2);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "编辑用户失败"
                });
            }
            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "编辑用户", request.Id, user.Mobile);
            return(new BaseApiResponse());
        }