Exemplo n.º 1
0
        public CartReturnModel CartReturn(Guid id)
        {
            var currentCart = RetrieveCart(id);

            if (currentCart == null)
            {
                return(null);
            }

            int totalPrice = 0;

            foreach (var item in currentCart.Items)
            {
                totalPrice += catalog.ItemPrice(item.Key) * item.Value;
            }

            return(new CartReturnModel {
                Items = currentCart.Items, TotalPrice = totalPrice
            });
        }
Exemplo n.º 2
0
        public OrderDetails GetOrders(Guid userId)
        {
            if (!UserExist(userId))
            {
                throw new Exception("User doesn't exist.");
            }

            if (!UserHasOrders(userId))
            {
                throw new Exception("User doesn't have orders.");
            }

            var userDetails = users.SingleOrDefault(f => f.UserId == userId);
            var usersOrders = orders[userId];

            var orderDetails = new OrderDetails()
            {
                FirstName = userDetails.FirstName,
                Surname   = userDetails.Surname
            };

            foreach (var order in usersOrders)
            {
                var items      = orderManager.GetOrder(order);
                var totalPrice = 0;

                foreach (var item in items)
                {
                    totalPrice += totalPrice += catalogManager.ItemPrice(item.Key) * item.Value;
                }

                orderDetails.Orders.Add(new OrderModel {
                    Items = items, TotalPrice = totalPrice
                });
            }

            return(orderDetails);
        }