private int CreateOrUpdateCurrentOrder(List <Purchase> basket) { int orderId; string customerId = (User as IUserPrincipal).Id; OrderDto order = _orderService.GetCurrentOrderForCustomer(customerId); if (order == null) { const int discount = 0; List <int> orderDetailsIds = basket.Select(b => _orderDetailsService.Create(b.GameId, b.Price, b.Quantity, discount)).ToList(); orderId = _orderService.Create(customerId, orderDetailsIds); } else { Dictionary <int, short> pairs = basket.ToDictionary(purchase => purchase.GameId, purchase => purchase.Quantity); _orderService.Update(order.Id, pairs, customerId); orderId = order.Id; } return(orderId); }