C
C#6mo ago
jlim

✅ wpf json CRUD(mvvm)

Could you tutorial how to use json config file ? I will do CRUD in the mvvm pattern through Json file.
42 Replies
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
leowest
leowest6mo ago
Imagine you have a User DTO (which represents the JSON of one of your endpoints)
public class UserDto
{
public Guid Id {get;set;}
public string Name {get;set;}
public int Age {get;set;}
}
public class UserDto
{
public Guid Id {get;set;}
public string Name {get;set;}
public int Age {get;set;}
}
And your API returns a list of Users for example... So you would be using HttpClient to communicate with your API via a service. As very barebone example imagine something like:
public class UserService
{
private readonly HttpClient _httpClient;
public UserService(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<List<UserDto>> GetUsers()
{
return await _httpClient.GetFromJsonAsync<UserDto>("your api endpoint");
}
}
public class UserService
{
private readonly HttpClient _httpClient;
public UserService(HttpClient httpClient)
{
_httpClient = httpClient;
}

public async Task<List<UserDto>> GetUsers()
{
return await _httpClient.GetFromJsonAsync<UserDto>("your api endpoint");
}
}
So in your mvvm you would have an instance of that service and u would call GetUsers to populate a ObservableCollection which would in turn populate your View. This is very barebone simplistic explanation just to give u an idea.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
leowest
leowest6mo ago
I don't think its a file but could be
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
leowest
leowest6mo ago
could be poor wording and language barrier
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
leowest
leowest6mo ago
so I gave an example using an API and if that is not what he wants im sure he will say 😉 regardless from httpclient to readfile is very little changes
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
Thanks your kindness reply, but I don't need Http client. Json file is located into my pc local I can't use DBMS like mysql, postgre. And factory's environment is can't use internet. So I wanna use configure file like json, xml.. And I wanna implemented CRUD in the json file. And yea' I think IOC is clear. If give me a guideline or solution then I will step up than before Thanks your kindness coding! But my intent is not using http
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
I see Oh I found FileUserservice!, I try it thanks!
leowest
leowest6mo ago
then I would suggest you use SQLite which is local and can be used with efcore
SleepWellPupper
SleepWellPupper6mo ago
SqLite uses a file also and provides more facilities suited to CRUD oh yeah me too slow
jlim
jlimOP6mo ago
But I would see your sharing
leowest
leowest6mo ago
"see your sharing"?
jlim
jlimOP6mo ago
I see. Actually I used mysql using efcore. But site's situation is not proper. So I thought use json instead of Mysql
leowest
leowest6mo ago
nah SQLite for sure 🙂 u could even install mysql locally or postgresql and not need internet it would work just in the same computer or in the factory intranet
jlim
jlimOP6mo ago
My English haha.. I will see that Ms materials you shared
leowest
leowest6mo ago
the term "no internet" can mean many things and sometimes it doesn't mean you cannot access a server inside the factory
SleepWellPupper
SleepWellPupper6mo ago
fyi SQLite does not require setting up a server, it is a simple file (like a json file).
jlim
jlimOP6mo ago
Oh ! It is good But my config is small. Haha about 10
leowest
leowest6mo ago
No description
jlim
jlimOP6mo ago
10 below. Config
leowest
leowest6mo ago
all in the red circle is no internet so if there are multiple pcs u can even make your own local server
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
Yea but why people use Mysql and Postgre? Because Dotnet support sqllight Sqllight is good tool than them isn't it?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
leowest
leowest6mo ago
SQLite is a great tool for small purpose MySQL is popularized because old days of php and webhosting and its performance is no where near MSSQL or PostgreSQL
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
We just using mysql for database (just saving datas)
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
You guys in my situation , recommend sqllite than other dbms?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
The important things , It can't need any setup!!
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
Yea I thought Json or xml as config file I see
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
Through app it is ok
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
jlim
jlimOP6mo ago
But Originally I thought note pade Also Anyway in my level, I do all things sqllite and json... lol Thanks your guys help to me
Want results from more Discord servers?
Add your server