public async Task <bool> DoActionPlayAsync(ActionOptionDTO actionOptionDTO) { //Set URI to the specific function API string url = $"{this.baseUri}/DoActionPlay"; try { //Call the server API string json = JsonSerializer.Serialize(actionOptionDTO); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(url, content); //Check status if (response.IsSuccessStatusCode) { return(true); } else { return(false); } } catch (Exception ex) { Console.WriteLine(ex); return(false); } }
public void DoActionPlay([FromBody] ActionOptionDTO actionOptionDTO) { PlayerDTO pDto = HttpContext.Session.GetObject <PlayerDTO>("player"); //Check if user logged in! if (pDto != null) { ActionOption actionOption = new ActionOption { OptioName = actionOptionDTO.OptioName, OptionEffect = actionOptionDTO.OptionEffect, OptionId = actionOptionDTO.OptionId }; context.DoActionPlay(actionOption, pDto.PlayerId); Response.StatusCode = (int)System.Net.HttpStatusCode.OK; } }
public override void Show() { base.Show(); try { // מציגים את רשימת המשחקים Task <List <ActionOptionDTO> > list = UIMain.api.GetAllFoodAsync(); ObjectsList foods = new ObjectsList("foods", list.Result.ToList <object>()); foods.Show(); Console.WriteLine(); Console.WriteLine("Please enter food option ID:"); int foodId = int.Parse(Console.ReadLine()); const int DEAD_STATUS_ID = 4; Task <List <PetDTO> > playerPets = UIMain.api.GetPlayerPetsAsync(); PetDTO p = playerPets.Result.Where(p => p.LifeStatusId != DEAD_STATUS_ID).FirstOrDefault(); ActionOptionDTO actionOptionDTO = list.Result.Where(a => a.OptionId == foodId).FirstOrDefault(); if (p == null) { Console.WriteLine("There is no active pet"); } else { Task <bool> task = UIMain.api.DoActionFeedAsync(actionOptionDTO); if (task.Result) { Console.WriteLine($"The pet ate {actionOptionDTO.OptioName}"); } else { Console.WriteLine("Something wrong happened!"); } } } catch (Exception e) { Console.Clear(); Console.WriteLine("Something wrong happened!"); Console.WriteLine($"Error message: {e.Message}"); } Console.WriteLine("Please press any key to get back to menu!"); Console.ReadKey(true); }