示例#1
0
 /// <summary>
 /// 获取用户头像链接, 结果赋给 <see cref="LoverCloudUserResource.ProfileImageUrl"/>
 /// </summary>
 /// <param name="user"></param>
 /// <param name="url"></param>
 public static void GetProfileImageUrl(
     this LoverCloudUserResource user, IUrlHelper url)
 {
     if (url == null)
     {
         throw new ArgumentNullException(nameof(url));
     }
     // 生成相对url路径, 因为生成环境可能使用反向代理
     user.ProfileImageUrl = url.LinkRelative("GetProfileImage", new { userId = user.Id });
 }
        public async Task <IActionResult> GetById([FromRoute] string id)
        {
            LoverCloudUser user = await _repository.FindByIdAsync(id);

            LoverCloudUserResource userResource = _mapper.Map <LoverCloudUserResource>(user);

            userResource.GetProfileImageUrl(Url);

            ExpandoObject shapedUser = userResource.ToDynamicObject("id, profileImageUrl, username");

            return(Ok(shapedUser));
        }