Ejemplo n.º 1
0
        public async Task <Result> Handle(UserAddCommand request, CancellationToken cancellationToken)
        {
            var type = Convert.ToInt32(request.Type);

            if (type == 0 && (
                    string.IsNullOrWhiteSpace(request.RealName) ||
                    string.IsNullOrWhiteSpace(request.IDCard) ||
                    string.IsNullOrWhiteSpace(request.Mobile)))
            {
                return(Result.Failure("姓名、身份证号码、手机号码不能为空!"));
            }

            if (await _userRepository.AnyAsync(x => x.UserName == request.UserName))
            {
                return(Result.Failure("用户名已存在"));
            }
            var pwd  = _md5.Md5(request.Password);
            var user = new User()
            {
                Password = pwd,
                UserName = request.UserName,
                Type     = type
            };

            if (type == 0 || type == 2)
            {
                user.RealName = request.RealName;
                user.IDCard   = request.IDCard;
                user.Mobile   = request.Mobile;
            }

            await _userRepository.AddAsync(user, cancellationToken);

            return(Result.Success());
        }
Ejemplo n.º 2
0
        public async Task <LoginUserDTO> Handle(LoginCommand request, CancellationToken cancellationToken)
        {
            var pwd = _md5.Md5(request.Password);

            _logger.LogInformation(pwd);
            var user = await _userRepository.GetAsync(x => x.UserName == request.UserName &&
                                                      x.Password == pwd);

            if (user == null)
            {
                return(null);
            }


            user.LoginCount++;
            user.LastLoginTime = DateTime.Now;
            await _userRepository.UpdateAsync(user);

            var dto = new LoginUserDTO();

            dto.UserName = user.UserName;
            dto.Id       = user.Id;
            dto.Type     = user.Type;

            var commpanyUser = await _companyUserRepository.GetAsync(x => x.UserId == user.Id);

            if (commpanyUser == null)
            {
                dto.CompanyName = "[未绑定企业]";
                dto.CompanyId   = 0;
            }
            else
            {
                var commpany = await _companyRepository.GetAsync(x => x.Id == commpanyUser.CompanyId);

                dto.CompanyId   = commpany.Id;
                dto.Logo        = commpany.Logo;
                dto.CompanyName = commpany.Name ?? "[未填写企业名称]";

                //更新登陆次数

                commpany.LoginCount++;
                await _companyRepository.UpdateAsync(commpany);
            }



            return(dto);
        }
Ejemplo n.º 3
0
        public async Task <Result> Handle(EditUserCommand request, CancellationToken cancellationToken)
        {
            var id   = Convert.ToInt32(request.Id);
            var user = await _userRepository.Set().FirstOrDefaultAsync(x => x.Id == id);

            if (user == null)
            {
                return(Result.Failure("用户不存在"));
            }

            var type = user.Type;

            if (type == 0 && (
                    string.IsNullOrWhiteSpace(request.RealName) ||
                    string.IsNullOrWhiteSpace(request.IDCard) ||
                    string.IsNullOrWhiteSpace(request.Mobile)))
            {
                return(Result.Failure("姓名、身份证号码、手机号码不能为空!"));
            }


            if (await _userRepository.AnyAsync(x => x.Id != id && x.UserName == request.UserName))
            {
                return(Result.Failure("用户名已存在"));
            }
            var pwd = _md5.Md5(request.Password);

            user.UserName = request.UserName;
            user.Password = pwd;

            if (type == 0)
            {
                user.RealName = request.RealName;
                user.IDCard   = request.IDCard;
                user.Mobile   = request.Mobile;
            }

            await _userRepository.UpdateAsync(user, cancellationToken);

            return(Result.Success());
        }