Brutal_Boost
Brutal_Boost
CC#
Created by Brutal_Boost on 1/21/2024 in #help
Where does .NET Core fit into the equation on web development?
Okay that makes sense. So you could use .NET core for a desktop app as well? It’s not only for web development?
11 replies
CC#
Created by Brutal_Boost on 1/14/2024 in #help
I have some questions about detecting the currently logged in user and how to handle it.
Awesome I will look into that. And correct it's WASM with a backend API
4 replies
CC#
Created by Brutal_Boost on 12/28/2023 in #help
Is there a way to get rid of the Task type on an object?
I guess I am struggling with how to go about getting it into list form for the front end. I went ahead and added the front end where I am trying to display the list. Basically I want to populate
List<Appetizer> appetizers = new List<Appetizer>();
List<Appetizer> appetizers = new List<Appetizer>();
with what the API returns.
@page "/appetizerlist"
@using AppChallenge.Entities
@using AppChallenge.Services
@inject AppetizerService appetizerService
@inject UserService userService

<PageTitle>AppetizerList</PageTitle>

<h3>AppetizerList</h3>


@foreach (var app in appetizers)
{
<p>
<h3><a href="/[email protected]_ID()}">@app.get_name()</a> </h3>
<p>@app.get_description()</p>
<h3>@userService.get_user(@app.get_user()).get_FirstName()</h3>
</p>
}

@code {

List<Appetizer> appetizers = new List<Appetizer>();

protected override void OnInitialized()
{
appetizers = appetizerService.GetAppetizerList();

}

}
@page "/appetizerlist"
@using AppChallenge.Entities
@using AppChallenge.Services
@inject AppetizerService appetizerService
@inject UserService userService

<PageTitle>AppetizerList</PageTitle>

<h3>AppetizerList</h3>


@foreach (var app in appetizers)
{
<p>
<h3><a href="/[email protected]_ID()}">@app.get_name()</a> </h3>
<p>@app.get_description()</p>
<h3>@userService.get_user(@app.get_user()).get_FirstName()</h3>
</p>
}

@code {

List<Appetizer> appetizers = new List<Appetizer>();

protected override void OnInitialized()
{
appetizers = appetizerService.GetAppetizerList();

}

}
29 replies
CC#
Created by Brutal_Boost on 12/28/2023 in #help
Is there a way to get rid of the Task type on an object?
So even if you don't return anything it still needs awaited?
29 replies
CC#
Created by Brutal_Boost on 12/28/2023 in #help
Is there a way to get rid of the Task type on an object?
GetAppetizerList is what is called externally.
29 replies
CC#
Created by Brutal_Boost on 12/28/2023 in #help
Is there a way to get rid of the Task type on an object?
How does this look outside of not using IHttpClientFactory:
using System.Security.Cryptography.X509Certificates;
using AppChallenge.Entities;
using Newtonsoft.Json;
using System.Linq;

namespace AppChallenge.Services
{
public class AppetizerService
{
private List<Appetizer> appetizers = new List<Appetizer>();

public static string BaseAddress = "http://127.0.0.1:5000";
static readonly string Url = $"{BaseAddress}/";

static HttpClient client = new HttpClient();

public async Task InitializeAppetizerServiceAsync()
{
GetAppetizers();

await Task.Delay(100);
}

public List<Appetizer> GetAppetizerList()
{
GetAppetizers();
return this.appetizers;
}

public async Task GetAppetizers()
{

var temp = await GetAllAppsFromApi();

this.appetizers = temp.ToList();
}

public static async Task<List<Appetizer>> GetAllAppsFromApi()
{
string result = await client.GetStringAsync($"{Url}api/all_apps");

return JsonConvert.DeserializeObject<List<Appetizer>>(result);
}

}
}
using System.Security.Cryptography.X509Certificates;
using AppChallenge.Entities;
using Newtonsoft.Json;
using System.Linq;

namespace AppChallenge.Services
{
public class AppetizerService
{
private List<Appetizer> appetizers = new List<Appetizer>();

public static string BaseAddress = "http://127.0.0.1:5000";
static readonly string Url = $"{BaseAddress}/";

static HttpClient client = new HttpClient();

public async Task InitializeAppetizerServiceAsync()
{
GetAppetizers();

await Task.Delay(100);
}

public List<Appetizer> GetAppetizerList()
{
GetAppetizers();
return this.appetizers;
}

public async Task GetAppetizers()
{

var temp = await GetAllAppsFromApi();

this.appetizers = temp.ToList();
}

public static async Task<List<Appetizer>> GetAllAppsFromApi()
{
string result = await client.GetStringAsync($"{Url}api/all_apps");

return JsonConvert.DeserializeObject<List<Appetizer>>(result);
}

}
}
29 replies
CC#
Created by Brutal_Boost on 12/28/2023 in #help
Is there a way to get rid of the Task type on an object?
Yeah I just learned about the clientfactory now and once I get this working I am going to implement that. I've tried doing
this.appetizers = await getAllAppsFromApi();
this.appetizers = await getAllAppsFromApi();
and it errors within the getAppetizers() method (will change the method names to pascal case also). I'm guessing getAppetizers() needs to be async as well?
29 replies