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 }); }
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); }