public static CartReadModel ReadCartReadModel(SqlDataReader reader, string userId)
        {
            var idx           = 0;
            var productId     = reader.AsInt64(idx++);
            var price         = reader.AsDecimal(idx++);
            var name          = reader.AsString(idx++);
            var discountPrice = reader.AsDecimalOrNull(idx++);
            var imageUrl      = reader.AsString(idx++);
            var id            = reader.AsInt64(idx++);
            var quantity      = reader.AsInt16(idx);

            var cartReadModel = new CartReadModel()
            {
                ProductId     = productId,
                Price         = price,
                Name          = name,
                DiscountPrice = discountPrice,
                Quantity      = quantity,
                ImageUrl      = imageUrl,
                UserId        = userId,
                Id            = id
            };

            return(cartReadModel);
        }
示例#2
0
        private static CategoryReadModel ReadCategoryReadModel(SqlDataReader reader)
        {
            var idx         = 0;
            var id          = reader.AsInt64(idx++);
            var productType = reader.AsString(idx);

            return(new CategoryReadModel()
            {
                Category = productType, Id = id
            });
        }
        private static async Task <ProductReadModel?> ReadProductAsync(SqlDataReader reader)
        {
            ProductReadModel?product = null;

            while (await reader.ReadAsync().ConfigureAwait(false)) //Todo CancellationTokens
            {
                var idx           = 0;
                var id            = reader.AsInt64(idx++);
                var brand         = reader.AsStringOrNull(idx++);
                var color         = reader.AsStringOrNull(idx++);
                var createTime    = reader.AsDateTimeOrNull(idx++);
                var description   = reader.AsStringOrNull(idx++);
                var discount      = reader.AsFloatOrNull(idx++);
                var expiration    = reader.AsDateTimeOrNull(idx++);
                var discountPrice = reader.AsDecimalOrNull(idx++);
                var isBaby        = reader.AsBooleanOrNull(idx++);
                var gender        = reader.AsEnumOrNull <Gender>(idx++);
                var isDeleted     = reader.AsBooleanOrNull(idx++);
                var name          = reader.AsStringOrNull(idx++);
                var price         = reader.AsDecimal(idx++);
                var quantity      = reader.AsByte(idx++);
                var productType   = reader.AsString(idx++);
                var weight        = reader.AsJsonOrNull <Weight>(idx++);
                var size          = reader.AsStringOrNull(idx++);
                var url           = reader.AsString(idx++);
                var isMainImage   = reader.AsBoolean(idx++);
                var imgId         = reader.AsInt64(idx++);
                var productId     = reader.AsInt64(idx);

                if (product is null)
                {
                    product = new ProductReadModel()
                    {
                        Id            = id,
                        Price         = price,
                        IsDeleted     = isDeleted,
                        Color         = color,
                        Brand         = brand,
                        ProductType   = productType,
                        Weight        = weight,
                        Name          = name,
                        Description   = description,
                        Gender        = gender,
                        ForBaby       = isBaby,
                        Size          = size,
                        Discount      = discount,
                        Quantity      = quantity,
                        CreateTime    = createTime,
                        DiscountPrice = discountPrice,
                        Expiration    = expiration,
                        Images        = new List <ProductReadModelImage>(6)
                        {
                            new () {
                                Id        = imgId,
                                Url       = url,
                                MainImage = isMainImage,
                                ProductId = productId,
                            }
                        }
                    };
                }
                else
                {
                    product.Images.Add(new()
                    {
                        Id        = imgId,
                        Url       = url,
                        MainImage = isMainImage,
                        ProductId = productId
                    });
                }
            }

            return(product);
        }