示例#1
0
        public static Basket Convert(CreateBasketDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            return(new Basket
            {
                User = UserConverter.Convert(dto.User),
                UserId = dto.User.Id
            });
        }
示例#2
0
        public static Basket Convert(BasketDTO basket)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            return(new Basket
            {
                Id = basket.Id,
                UserId = basket.User.Id,
                BasketItems = BasketItemsConverter.Convert(basket.BasketItems),
                User = UserConverter.Convert(basket.User)
            });
        }
示例#3
0
        public static OrderDTO Convert(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            return(new OrderDTO
            {
                Id = order.Id,
                Comment = order.Comment,
                User = UserConverter.Convert(order.User),
                OrderItems = OrderItemsConverter.Convert(order.OrderItems),
                TotalPrice = order.OrderItems.Select(p => p.Product.Price).Sum()
            });
        }
示例#4
0
        public static Order Convert(CreateOrderDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            return(new Order
            {
                Comment = dto.Comment,
                User = UserConverter.Convert(dto.User),
                UserId = dto.User.Id,
                OrderItems = OrderItemsConverter.Convert(dto.OrderItems),
                TotalPrice = dto.OrderItems.Select(p => p.Product.Price).Sum()
            });
        }
示例#5
0
        public static BasketDTO Convert(Basket basket)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var dto = new BasketDTO
            {
                Id   = basket.Id,
                User = UserConverter.Convert(basket.User)
            };

            if (basket.BasketItems != null)
            {
                dto.BasketItems = BasketItemsConverter.Convert(basket.BasketItems);
            }
            return(dto);
        }