Skip to content

Commit 459c134

Browse files
Initial commit.
0 parents  commit 459c134

File tree

87 files changed

+83636
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+83636
-0
lines changed

.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Ignore build outputs
2+
bin/
3+
obj/
4+
*.dll
5+
*.exe
6+
*.pdb
7+
8+
# Ignore user-specific files
9+
*.user
10+
*.suo
11+
*.userosscache
12+
*.sln.docstates
13+
14+
# Ignore logs and temporary files
15+
*.log
16+
*.tmp
17+
*.temp
18+
*.cache
19+
*.vs/
20+
.idea/
21+
22+
# Ignore Angular build outputs
23+
Client/dist/
24+
Client/node_modules/
25+
Client/.angular/
26+
Client/.cache/
27+
28+
# Ignore environment files
29+
Client/src/environments/environment*.ts
30+
Service/appsettings*.json
31+
32+
# Ignore Docker files
33+
*.pid
34+
*.log
35+
docker-compose.override.yml
36+
37+
# Ignore EF Core migrations
38+
Service/Migrations/
39+
40+
# Ignore OS-specific files
41+
.DS_Store
42+
Thumbs.db
43+
desktop.ini
44+
45+
# Ignore npm debug files
46+
npm-debug.log*
47+
yarn-debug.log*
48+
yarn-error.log*
49+
50+
# Ignore coverage reports
51+
coverage/
52+
Client/coverage/
53+
54+
# Ignore generated files
55+
*.generated.cs

.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run server",
6+
"type": "dotnet",
7+
"request": "launch",
8+
"projectPath": "${workspaceFolder}/CompareUsers/CompareUsers.csproj"
9+
},
10+
{
11+
"name": "Docker build and run",
12+
"type": "node",
13+
"request": "launch",
14+
"program": "${workspaceFolder}/server.js",
15+
"preLaunchTask": "docker-run",
16+
"cwd": "${workspaceFolder}",
17+
"console": "integratedTerminal",
18+
"internalConsoleOptions": "neverOpen"
19+
},
20+
{
21+
"name": "Docker build github",
22+
"type": "node",
23+
"request": "launch",
24+
"program": "${workspaceFolder}/server.js",
25+
"preLaunchTask": "docker-ghcr-push",
26+
"cwd": "${workspaceFolder}",
27+
"console": "integratedTerminal",
28+
"internalConsoleOptions": "neverOpen"
29+
}
30+
]
31+
}

.vscode/tasks.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "dotnet build",
6+
"type": "shell",
7+
"command": "dotnet build",
8+
"problemMatcher": "$msCompile"
9+
},
10+
{
11+
"label": "dotnet publish",
12+
"type": "shell",
13+
"command": "dotnet publish -c Release -o ./publish",
14+
"problemMatcher": "$msCompile",
15+
"dependsOn": "dotnet build"
16+
},
17+
{
18+
"label": "build-and-publish",
19+
"dependsOn": [
20+
"dotnet build",
21+
"dotnet publish"
22+
]
23+
},
24+
{
25+
"label": "docker-build",
26+
"type": "shell",
27+
"command": "docker build -t compareusers .",
28+
"problemMatcher": []
29+
},
30+
{
31+
"label": "docker-run",
32+
"type": "shell",
33+
"command": "docker run -d -p 8080:80 --name compareusers compareusers",
34+
"group": {
35+
"kind": "build",
36+
"isDefault": true
37+
},
38+
"problemMatcher": [],
39+
"dependsOn": "docker-build"
40+
},
41+
{
42+
"label": "docker-ghcr-login",
43+
"type": "shell",
44+
"command": "docker login --username <USERNAME> --password <PERSONAL_ACCESS_TOKEN> ghcr.io",
45+
"problemMatcher": []
46+
},
47+
{
48+
"label": "docker-ghcr-build",
49+
"type": "shell",
50+
"command": "docker build -t ghcr.io/primaryobjects/compare-users:latest .",
51+
"problemMatcher": [],
52+
"dependsOn": "docker-ghcr-login"
53+
},
54+
{
55+
"label": "docker-ghcr-push",
56+
"type": "shell",
57+
"command": "docker push ghcr.io/primaryobjects/compare-users:latest",
58+
"problemMatcher": [],
59+
"dependsOn": "docker-ghcr-build"
60+
}
61+
]
62+
}

CompareUsers.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="CompareUsers/CompareUsers.csproj" />
3+
</Solution>

CompareUsers/CompareUsers.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>

CompareUsers/Data/updates.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[
2+
{
3+
"_id": "67f85f0a18370065174e9d29",
4+
"index": 0,
5+
"isActive": true,
6+
"balance": "$3,252.63",
7+
"age": 39,
8+
"name": "Caroline Page",
9+
"gender": "female",
10+
"company": "GAZAK",
11+
"email": "carolinepage@gazak.com",
12+
"phone": "+1 (857) 410-2812",
13+
"address": "241 Harway Avenue, Cotopaxi, Delaware, 1977"
14+
},
15+
{
16+
"_id": "67f85f0ae75980488f63dced",
17+
"index": 4,
18+
"isActive": true,
19+
"balance": "$2,729.85",
20+
"age": 39,
21+
"name": "Lara James",
22+
"gender": "female",
23+
"company": "STEELTAB",
24+
"email": "larajames@steeltab.com",
25+
"phone": "+1 (988) 410-2050",
26+
"address": "191 Jewel Street, Longoria, Colorado, 6878"
27+
},
28+
{
29+
"_id": "0",
30+
"index": 9,
31+
"isActive": false,
32+
"balance": "$9,999.68",
33+
"age": 32,
34+
"name": "Alice Doe",
35+
"gender": "female",
36+
"company": "REPLY",
37+
"email": "alice.doe@reply.com",
38+
"phone": "+1 (215) 432-9057",
39+
"address": "109 Main Ave, Philadelhia, Pennsylvania, 19103"
40+
}
41+
]

CompareUsers/Data/users.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[
2+
{
3+
"_id": "67f85f0a18370065174e9d29",
4+
"index": 0,
5+
"isActive": true,
6+
"balance": "$3,252.63",
7+
"age": 39,
8+
"name": "Caroline Page",
9+
"gender": "female",
10+
"company": "GAZAK",
11+
"email": "carolinepage@gazak.com",
12+
"phone": "+1 (857) 410-2812",
13+
"address": "241 Harway Avenue, Cotopaxi, Delaware, 1977"
14+
},
15+
{
16+
"_id": "67f85f0a901f942ae62168bd",
17+
"index": 1,
18+
"isActive": false,
19+
"balance": "$2,094.70",
20+
"age": 23,
21+
"name": "Kim Marks",
22+
"gender": "male",
23+
"company": "AFFLUEX",
24+
"email": "kimmarks@affluex.com",
25+
"phone": "+1 (894) 462-2519",
26+
"address": "122 Canal Avenue, Sunbury, Puerto Rico, 4008"
27+
},
28+
{
29+
"_id": "67f85f0a60f81bbff490997b",
30+
"index": 2,
31+
"isActive": true,
32+
"balance": "$2,137.62",
33+
"age": 32,
34+
"name": "Moss Small",
35+
"gender": "male",
36+
"company": "VOLAX",
37+
"email": "mosssmall@volax.com",
38+
"phone": "+1 (856) 594-3534",
39+
"address": "812 Huntington Street, Fannett, District Of Columbia, 9294"
40+
},
41+
{
42+
"_id": "67f85f0ae75980488f63dced",
43+
"index": 3,
44+
"isActive": true,
45+
"balance": "$2,729.85",
46+
"age": 39,
47+
"name": "Lara James",
48+
"gender": "female",
49+
"company": "STEELTAB",
50+
"email": "larajames@steeltab.com",
51+
"phone": "+1 (988) 410-2050",
52+
"address": "191 Jewel Street, Longoria, Colorado, 6878"
53+
},
54+
{
55+
"_id": "67f85f0af3ac7803b4661755",
56+
"index": 4,
57+
"isActive": false,
58+
"balance": "$2,467.68",
59+
"age": 22,
60+
"name": "Quinn Craig",
61+
"gender": "male",
62+
"company": "GOLISTIC",
63+
"email": "quinncraig@golistic.com",
64+
"phone": "+1 (947) 419-3042",
65+
"address": "104 Bancroft Place, Lopezo, American Samoa, 1288"
66+
},
67+
{
68+
"_id": "67f85f0a0c981bbc083b10d8",
69+
"index": 5,
70+
"isActive": false,
71+
"balance": "$2,431.97",
72+
"age": 39,
73+
"name": "Adele Stanley",
74+
"gender": "female",
75+
"company": "COWTOWN",
76+
"email": "adelestanley@cowtown.com",
77+
"phone": "+1 (873) 534-3776",
78+
"address": "133 Everett Avenue, Roosevelt, Nevada, 2410"
79+
}
80+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
using CompareUsers.Types;
8+
9+
namespace CompareUsers.Managers
10+
{
11+
public static class UserManager
12+
{
13+
private static JsonSerializerOptions _jsonSerializerOptions = new()
14+
{
15+
PropertyNameCaseInsensitive = true,
16+
Converters =
17+
{
18+
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
19+
}
20+
};
21+
22+
public static IEnumerable<User> GetUsers(string json)
23+
{
24+
return JsonSerializer.Deserialize<IEnumerable<User>>(json, _jsonSerializerOptions) ?? [];
25+
}
26+
27+
public static Tuple<List<User>, List<User>> GetInsertedUpdatedUsers(IEnumerable<User> existingUsers, IEnumerable<User> modifiedUsers)
28+
{
29+
// If a modified user id is 0, it is a new user.
30+
// Otherwise, compare all fields in the modified user against the matching existing user to check for a change.
31+
// Return a tuple of new and updated users.
32+
List<User> newUsers = [];
33+
List<User> updatedUsers = [];
34+
35+
foreach (User user in modifiedUsers)
36+
{
37+
if (user.Id == "0")
38+
{
39+
newUsers.Add(user);
40+
}
41+
else
42+
{
43+
var existingUser = existingUsers.FirstOrDefault(u => u.Id == user.Id);
44+
if (existingUser != null && !existingUser.Equals(user))
45+
{
46+
updatedUsers.Add(user);
47+
}
48+
}
49+
}
50+
51+
return new Tuple<List<User>, List<User>>(newUsers, updatedUsers);
52+
}
53+
54+
private static bool AreUsersEqualByProperties(User user1, User user2)
55+
{
56+
if (user1 == null || user2 == null)
57+
return false;
58+
59+
var properties = typeof(User).GetProperties();
60+
foreach (var property in properties)
61+
{
62+
var value1 = property.GetValue(user1);
63+
var value2 = property.GetValue(user2);
64+
65+
if (!Equals(value1, value2))
66+
{
67+
return false;
68+
}
69+
}
70+
71+
return true;
72+
}
73+
}
74+
}

CompareUsers/Pages/Error.cshtml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>

0 commit comments

Comments
 (0)