Exemplo n.º 1
0
        public static BasketDto MapToBasketDto(Domain.Entities.BasketEntity basketEntityEntity)
        {
            // Transform BasketEntity to BasketDto
            var basketDto = new BasketDto();

            basketDto.BasketId  = basketEntityEntity.BasketId;
            basketDto.ItemCount = basketEntityEntity.Count;

            foreach (var item in basketEntityEntity.Items)
            {
                basketDto.CartItems.Add(new BasketItemDto
                {
                    ProductId = item.ProductId,
                    Name      = item.Title,
                    Artist    = item.Artist,
                    Genre     = item.Genre,
                    //ParentalCaution = item.ParentalCaution,
                    QuanityOrdered = item.Quantity,
                    Price          = TransformUnitPrice(item.UnitPrice, item.Quantity),
                }
                                        );

                basketDto.CartTotal = basketDto.CartItems.Sum(x => x.Price);
            }

            return(basketDto);
        }
Exemplo n.º 2
0
        public static List <BasketDto> MapToBasketDto(IEnumerable <Domain.Entities.BasketEntity> baskets)
        {
            var totalPrice = 0m;
            var basketDtos = new List <BasketDto>();

            foreach (var basket in baskets)
            {
                var basketDto = new BasketDto
                {
                    BasketId = basket.BasketId
                };

                foreach (var item in basket.Items)
                {
                    basketDto.CartItems.Add(new BasketItemDto
                    {
                        ProductId = item.ProductId,
                        Name      = item.Title,
                        Artist    = item.Artist,
                        Genre     = item.Genre,
                        //ParentalCaution = item.ParentalCaution,
                        QuanityOrdered = item.Quantity,
                        //Price = decimal.Parse(item.UnitPrice) * item.Quantity,
                        Price = TransformUnitPrice(item.UnitPrice, item.Quantity),
                    }
                                            );

                    basketDto.CartTotal = basketDto.CartItems.Sum(x => x.Price * x.QuanityOrdered);
                }

                basketDtos.Add(basketDto);
            }

            return(basketDtos);
        }