public async Task CRUD_BetEvent_Test() { var client = new BetEventClient("http://localhost:27254"); var createdEvent = await client.CreateAsync(new BetEventMeta { Name = "Alex", BetDeadline = DateTime.Now, Outcomes = "kdsmd", CreatorId = 0 }); var k = await client.CloseEventAsync(createdEvent.Id, "dmls"); var allEvents = await client.GetAllAsync(); var anotherCreatedEvent = await client.CreateAsync(new BetEventMeta { Name = "Steven", BetDeadline = DateTime.Now, Outcomes = "ksmck", CreatorId = 1 }); var updatedEvent = await client.UpdateAsync(new Models.BetEvent { Id = createdEvent.Id, Name = "Sam", Description = "Apple", BetDeadline = DateTime.Now, Outcomes = "ksdn" }); var newEvent = await client.GetAsync(updatedEvent.Id); var deletedEvent = await client.DeleteAsync(newEvent.Id); var allEventsAfterDeletion = await client.GetAllAsync(); Console.WriteLine(allEventsAfterDeletion); }
public async Task ExecuteAsync(UserMessage message) { var state = stateService.GetCurrentState(message.User); var eventClient = new BetEventClient("http://localhost:27254"); var betClient = new BetClient("http://localhost:27254"); if (state is CloseEventCommandState closeState) { switch (closeState.State) { case CloseEventState.EventChoosing: var allEvents = await eventClient.GetAllEventsFromCreatorAsync(message.TelegramMessage.From.Id); int chosenEventNumber; if (!Int32.TryParse(message.Tail, out chosenEventNumber)) { await client.SendTextMessageAsync(message.TelegramMessage.Chat, "введите, пожалуйста, номер цифрами"); break; } if (chosenEventNumber < 1 || chosenEventNumber > allEvents.Length) { await client.SendTextMessageAsync(message.TelegramMessage.Chat, "Введите, пожалуйста, существующий номер ставки"); break; } var chosenEvent = await eventClient.GetAsync((closeState.IdDictionary[chosenEventNumber])); await client.SendTextMessageAsync(message.TelegramMessage.Chat, $"Событие {chosenEventNumber} - {chosenEvent.Name}\n" + $"Исходы:\n" + $"{chosenEvent.Outcomes}\n" + $"Дедлайн: {chosenEvent.BetDeadline}\n" + $"Описание: {chosenEvent.Description}\n" + $"----------------\n" + $" Выберите произошедший исход"); stateService.SaveState(message.User, new CloseEventCommandState() { State = CloseEventState.WinningOutcome, ChosenEventId = chosenEvent.Id }); break; case CloseEventState.WinningOutcome: var chosenOutcome = message.Tail; var myEvent = await eventClient.GetAsync(closeState.ChosenEventId); var myEventOutcomes = myEvent.Outcomes.Split('\n'); if (!myEventOutcomes.Contains(chosenOutcome)) { await client.SendTextMessageAsync(message.TelegramMessage.Chat, "Введите, пожалуйста, существующий исход"); break; } await eventClient.CloseEventAsync(closeState.ChosenEventId, chosenOutcome); stateService.DeleteState(message.User); await client.SendTextMessageAsync(message.TelegramMessage.Chat, "Событие успешно закрыто"); break; } } else { var allEvents = await eventClient.GetAllEventsFromCreatorAsync(message.TelegramMessage.From.Id); var allEventsString = new StringBuilder(); var i = 1; var dictionary = new ConcurrentDictionary <int, Guid>(); if (allEvents.Length == 0) { await client.SendTextMessageAsync(message.TelegramMessage.Chat, $"Событий пока нет, чтобы предложить свое событие, напиши /createevent"); return; } foreach (var oneEvent in allEvents) { dictionary[i] = oneEvent.Id; allEventsString.Append($"{i} - {oneEvent.Name}\n" + $"Исходы: {oneEvent.Outcomes}\n" + $"Дедлайн: {oneEvent.BetDeadline}\n" + $"Описание: {oneEvent.Description}\n" + $"----------------\n"); i++; } await client.SendTextMessageAsync(message.TelegramMessage.Chat, $"{allEventsString.ToString()} \n Введите номер события, которое хотите закрыть"); stateService.SaveState(message.User, new CloseEventCommandState() { State = CloseEventState.EventChoosing, IdDictionary = dictionary }); } }