public Domain.ValueObject.User ToUser(string jsonData) { JsonResponseReader reader = new JsonResponseReader(jsonData); string userIdstr = reader.GetString("userId"); string userName = reader.GetString("userName"); string availableBalanceStr = reader.GetString("availableBalance"); if (userIdstr == null) { throw new NoNullAllowedException("未能正常解析用户ID"); } if (userName == null) { throw new NoNullAllowedException("未能正常解析用户名"); } decimal availableBalance; if (availableBalanceStr == null || !decimal.TryParse(availableBalanceStr, out availableBalance)) { throw new NoNullAllowedException("未能正常解析可用余额"); } var user = new Domain.ValueObject.User(userIdstr, userName, availableBalance); return(user); }
public VkPhoto[] GetPhoto(long userId, long albumId) { string response = caller.Get(new Uri(string.Format(_getUserPhotosUri, userId, albumId))); if (string.IsNullOrEmpty(response)) return (VkPhoto[]) null; ResponseGetUserPhotos responseGetUserPhotos = new JsonResponseReader<ResponseGetUserPhotos>().ReadResponse(response); if (responseGetUserPhotos == null || responseGetUserPhotos.Photos == null) return (VkPhoto[]) null; return responseGetUserPhotos.Photos; }
public Domain.ValueObject.Product ToProduct(string jsonData) { JsonResponseReader reader = new JsonResponseReader(jsonData); string productIdstr = reader.GetString("productId"); string saleName = reader.GetString("saleName"); string shoppePriceStr = reader.GetString("shoppePrice"); string salePriceStr = reader.GetString("salePrice"); string saleDescription = reader.GetString("saleDescription"); string stockStr = reader.GetString("stock"); Guid productId; if (productIdstr == null || !Guid.TryParse(productIdstr, out productId)) { throw new NoNullAllowedException("未能正常解析商品ID"); } if (saleName == null) { throw new NoNullAllowedException("未能正常解析销售名称"); } decimal shoppePrice; if (shoppePriceStr == null || !decimal.TryParse(shoppePriceStr, out shoppePrice)) { throw new NoNullAllowedException("未能正常解析专柜价"); } decimal salePrice; if (salePriceStr == null || !decimal.TryParse(salePriceStr, out salePrice)) { throw new NoNullAllowedException("未能正常解析销售价"); } if (saleDescription == null) { throw new NoNullAllowedException("未能正常解析销售描述"); } int stock; if (stockStr == null || !int.TryParse(stockStr, out stock)) { throw new NoNullAllowedException("未能正常解析库存"); } var product = new Domain.ValueObject.Product(productId, saleName, shoppePrice, salePrice, saleDescription, stock); return(product); }
public VkAlbum[] GetAlbum(long userId) { string response = caller.Get(new Uri(string.Format(_getUserAlbumsUri, userId))); if (string.IsNullOrEmpty(response)) return (VkAlbum[]) null; ResponseGetUserAlbums responseGetUserAlbums = new JsonResponseReader<ResponseGetUserAlbums>().ReadResponse(response); if (responseGetUserAlbums == null || responseGetUserAlbums.Albums == null) return (VkAlbum[]) null; foreach (VkAlbum vkAlbum in responseGetUserAlbums.Albums) { VkPhoto[] photo = GetPhoto(userId, vkAlbum.AlbumId); if (photo != null) vkAlbum.Photos = Enumerable.ToList<VkPhoto>((IEnumerable<VkPhoto>) photo); } return responseGetUserAlbums.Albums; }
public UserRoleRelation ToUserRoleRelation(string jsonData) { JsonResponseReader reader = new JsonResponseReader(jsonData); string userId = reader.GetString("userId"); string roleId = reader.GetString("roleId"); if (userId == null) { throw new NoNullAllowedException("未能正常解析用户ID"); } if (roleId == null) { throw new NoNullAllowedException("未能正常解析等级ID"); } var user = new UserRoleRelation(userId, roleId); return(user); }
public Wallet ToWallet(string jsonData) { JsonResponseReader reader = new JsonResponseReader(jsonData); string idstr = reader.GetString("id"); string userId = reader.GetString("userId"); string availableBalanceStr = reader.GetString("availableBalance"); string availableScoreStr = reader.GetString("availableScore"); if (idstr == null) { throw new NoNullAllowedException("未能正常解析钱包ID"); } if (userId == null) { throw new NoNullAllowedException("未能正常解析用户ID"); } decimal availableBalance; if (availableBalanceStr == null || !decimal.TryParse(availableBalanceStr, out availableBalance)) { throw new NoNullAllowedException("未能正常解析可用余额"); } int availableScore; if (availableScoreStr == null || !int.TryParse(availableScoreStr, out availableScore)) { throw new NoNullAllowedException("未能正常解析可用积分"); } var wallet = new Wallet(idstr, userId, availableBalance, availableScore); return(wallet); }
public VkUser GetVkUser(long userId) { var response = caller.Get(new Uri(string.Format(_getUserDetailsUri, userId))); if (string.IsNullOrEmpty(response)) return null; var responseGetUser = new JsonResponseReader<ResponseGetUser>().ReadResponse(response); if (responseGetUser == null || !responseGetUser.Users.Any()) return null; return responseGetUser.Users.First(); }