-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
84 lines (73 loc) · 2.37 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
namespace dailywords_Robot
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public static void MyUsers(User user)
{
string path = "users.json";
var temp = File.ReadAllText(path);
var readUseres = JsonConvert.DeserializeObject<AllUsers>(temp);
if (readUseres is null)
{
var newUsers = new AllUsers();
newUsers.Myusers.Add(user);
var data = JsonConvert.SerializeObject(newUsers);
File.WriteAllText(path, data);
}
else if (!readUseres.Myusers.Exists(usr => usr.userID == user.userID))
{
readUseres.Myusers.Add(user);
var data = JsonConvert.SerializeObject(readUseres);
File.WriteAllText(path, data);
}
}
public class User
{
public string fullName { get; set; }
public long userID { get; set; }
public string date { get; set; }
public User(string fullName, long userID, string date)
{
this.fullName = fullName;
this.userID = userID;
this.date = date;
}
}
public class AllUsers
{
public List<User> Myusers { get; set; }
public AllUsers()
{
this.Myusers = new List<User>();
}
}
public static int Count()
{
string path = "users.json";
string temp = File.ReadAllText(path);
var myusers = JsonConvert.DeserializeObject<AllUsers>(temp);
if (myusers is null) return 0;
return myusers.Myusers.Count;
}
}
}