Пример #1
0
        public async Task <ReporterOutput> AddReporter(ReporterAddInput input)
        {
            // 判断用户是否被占用
            var existUser = _userTbRepo.FirstOrDefault(u => u.Id == input.UserId);

            if (existUser == null || existUser.Enable == true)
            {
                throw new UserFriendlyException("用户不存在、或被占用");
            }

            var addReoirterObj = new ReporterInfoTb()
            {
                Address  = input.Address,
                AreaCode = input.AreaCode,
                Name     = input.Name,
                Phone    = input.Phone,
                User     = existUser,
                Age      = input.Age,
                Remark   = input.Remark,
                Type     = input.Type
            };

            var id = await _reporterInfoTbRepo.InsertAndGetIdAsync(addReoirterObj);

            addReoirterObj.Id = id;

            existUser.Enable = true;

            _userTbRepo.Update(existUser);

            return(addReoirterObj.MapTo <ReporterOutput>());
        }
        public async Task <UserAccountOutput> GetUserAccountById(Guid id)
        {
            var            existUser     = _userRepo.FirstOrDefault(u => u.Id == id);
            ReporterInfoTb existReporter = null;

            if (existUser == null)
            {
                existReporter = _reporterInfoRepo.FirstOrDefault(r => r.Id == id);
                if (existReporter == null)
                {
                    throw new UserFriendlyException("没有此用户账号信息");
                }
            }
            if (existReporter == null)
            {
                var bindReporter = await _reporterInfoRepo.FirstOrDefaultAsync(r => r.User.Id == existUser.Id);

                if (bindReporter == null)
                {
                    return(new UserAccountOutput()
                    {
                        User = existUser.MapTo <UserTbOutputDto>()
                    });
                }
                var result = new UserAccountOutput()
                {
                    Address  = bindReporter.Address,
                    AreaCode = bindReporter.AreaCode,
                    Id       = bindReporter.Id,
                    Name     = bindReporter.Name,
                    Phone    = bindReporter.Phone,
                    Photo    = bindReporter.Photo,
                    Age      = bindReporter.Age,
                    Remark   = bindReporter.Remark,
                    Type     = bindReporter.Type,
                    User     = existUser.MapTo <UserTbOutputDto>()
                };

                return(result);
            }
            else
            {
                var result = new UserAccountOutput()
                {
                    Address  = existReporter.Address,
                    AreaCode = existReporter.AreaCode,
                    Id       = existReporter.Id,
                    Name     = existReporter.Name,
                    Phone    = existReporter.Phone,
                    Photo    = existReporter.Photo,
                    Age      = existReporter.Age,
                    Remark   = existReporter.Remark,
                    Type     = existReporter.Type,
                    User     = existReporter.User.MapTo <UserTbOutputDto>()
                };
                return(result);
            }
        }