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);
        }
Exemple #2
0
        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);
        }
Exemple #4
0
        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);
        }