An example of comparing objects from two datasets in C# .NET.
The CompareUsers project is a web application built using ASP.NET Core Razor Pages. It allows users to compare two sets of JSON data representing user information. The application identifies and displays newly inserted users and updated users based on the comparison.
- Run the following command to launch using Docker.
docker run --name compare-users-container -d -p 8080:80 ghcr.io/primaryobjects/compare-users:latest
- Upload or paste JSON data for existing users and updated/inserted users.
- Compare the two datasets to identify:
- New Users: Users that are present in the updated dataset but not in the existing dataset.
- Updated Users: Users whose details have changed in the updated dataset compared to the existing dataset.
- Display results dynamically on the page.
- Prettify and format JSON input for better readability.
- ASP.NET Core Razor Pages: For building the web application.
- Materialize CSS: For responsive and modern UI design.
- System.Text.Json: For JSON parsing and serialization.
- C# Reflection: For dynamic property comparison of user objects.
- .NET 6 SDK or later
- A code editor like Visual Studio or Visual Studio Code
- Clone the repository.
- In VS Code, run the Run server or Docker build and run launch task.
- Open your browser and navigate to the url on localhost.
- Enter JSON data for Existing Users and Updated/Inserted Users in the provided text areas.
- Click the Submit button to compare the datasets.
- View the results:
- Inserted Users: Displayed in the "Inserted Users" section.
- Updated Users: Displayed in the "Updated Users" section.
- If there are errors in the JSON format, they will be displayed at the bottom of the page.
- Pages: Contains Razor Pages (Index.cshtml and Index.cshtml.cs) for the UI and backend logic.
- Managers: Contains the UserManager class for handling user comparison logic.
- Types: Contains the User class and related models.
- User:
- Represents a user object with properties like Id, Name, Email, etc.
- Includes methods for comparing user objects.
- UserManager:
- Provides methods for parsing JSON data and comparing user datasets.
- Key methods:
- GetUsers(string json): Parses JSON into a list of User objects.
- GetInsertedUpdatedUsers(IEnumerable existingUsers, IEnumerable modifiedUsers): Compares two datasets and returns new and updated users.
The JSON input should be an array of user objects with the following structure:
[
{
"_id": "12345",
"name": "John Doe",
"email": "john.doe@example.com",
"company": "ExampleCorp",
"isActive": true,
"age": 30,
"balance": "$1,234.56",
"gender": "male",
"phone": "123-456-7890",
"address": "123 Main St"
}
]
MIT
Kory Becker https://primaryobjects.com