public async Task StoreSessions(bool storeCompletedSessionsWithNoItems = true) { var storageTasks = new List <Task>(); foreach (var session in Sessions) { switch (session.Status) { case "COMPLETED": if (session.Items.Count > 0) { storageTasks.Add(sessionStore.PutSession(session)); } else if (storeCompletedSessionsWithNoItems) { storageTasks.Add(sessionStore.PutSession(session)); } else { storageTasks.Add(sessionStore.DeleteSession(session.Id)); } break; default: storageTasks.Add(sessionStore.PutSession(session)); break; } } await Task.WhenAll(storageTasks); }