Repository navigation
Expand file tree
/
Copy pathDataSeeder.cs
More file actions
195 lines (182 loc) · 6.51 KB
/
Copy pathDataSeeder.cs
File metadata and controls
195 lines (182 loc) · 6.51 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// DataSeeder.cs - Sample Data for Testing
using MongoDB.Bson;
using YourApp.Models;
using YourApp.Services;
namespace YourApp.Data
{
public class DataSeeder
{
private readonly ICacheDocumentService _service;
public DataSeeder(ICacheDocumentService service)
{
_service = service;
}
public async Task SeedSampleDataAsync()
{
// Check if data already exists
var existing = await _service.GetAllAsync();
if (existing.Any())
{
Console.WriteLine("Sample data already exists. Skipping seeding.");
return;
}
var sampleDocuments = new List<CacheDocument>
{
new CacheDocument
{
Data = new BsonDocument
{
{ "name", "John Doe" },
{ "age", 30 },
{ "email", "john.doe@example.com" },
{ "isActive", true },
{ "department", "Engineering" },
{ "salary", 75000.50 },
{ "startDate", DateTime.Parse("2020-01-15") }
}
},
new CacheDocument
{
Data = new BsonDocument
{
{ "name", "Jane Smith" },
{ "age", 28 },
{ "email", "jane.smith@example.com" },
{ "isActive", true },
{ "department", "Marketing" },
{ "salary", 65000.75 },
{ "startDate", DateTime.Parse("2021-03-10") },
{ "skills", new BsonArray { "Social Media", "Analytics", "Content Creation" } }
}
},
new CacheDocument
{
Data = new BsonDocument
{
{ "name", "Bob Johnson" },
{ "age", 45 },
{ "email", "bob.johnson@example.com" },
{ "isActive", false },
{ "department", "Sales" },
{ "salary", 85000.00 },
{ "startDate", DateTime.Parse("2018-07-20") },
{ "region", "West Coast" },
{ "quotaAchieved", true }
}
},
new CacheDocument
{
Data = new BsonDocument
{
{ "productName", "Widget Pro" },
{ "price", 299.99 },
{ "inStock", true },
{ "category", "Electronics" },
{ "rating", 4.5 },
{ "reviews", 1250 },
{ "features", new BsonArray { "Wireless", "Waterproof", "Long Battery" } }
}
},
new CacheDocument
{
Data = new BsonDocument
{
{ "orderNumber", "ORD-2024-001" },
{ "customerName", "Alice Cooper" },
{ "orderTotal", 1299.99 },
{ "orderDate", DateTime.Parse("2024-01-15") },
{ "status", "Shipped" },
{ "items", new BsonDocument
{
{ "laptop", 1 },
{ "mouse", 2 },
{ "keyboard", 1 }
}
},
{ "shippingAddress", new BsonDocument
{
{ "street", "123 Main St" },
{ "city", "Anytown" },
{ "state", "CA" },
{ "zipCode", "12345" }
}
}
}
}
};
foreach (var document in sampleDocuments)
{
await _service.CreateAsync(document);
}
Console.WriteLine($"Seeded {sampleDocuments.Count} sample documents successfully!");
}
}
}
// Program.cs modifications for seeding
/*
// Add to your Program.cs after services configuration and before app.Run()
// Seed sample data in development
if (app.Environment.IsDevelopment())
{
using (var scope = app.Services.CreateScope())
{
var seeder = new DataSeeder(scope.ServiceProvider.GetRequiredService<ICacheDocumentService>());
await seeder.SeedSampleDataAsync();
}
}
*/
// Package.json dependencies for Angular project
/*
{
"dependencies": {
"@angular/animations": "^16.0.0",
"@angular/common": "^16.0.0",
"@angular/compiler": "^16.0.0",
"@angular/core": "^16.0.0",
"@angular/forms": "^16.0.0",
"@angular/platform-browser": "^16.0.0",
"@angular/platform-browser-dynamic": "^16.0.0",
"@angular/router": "^16.0.0",
"ag-grid-angular": "^30.0.0",
"ag-grid-community": "^30.0.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.0.0",
"@angular/cli": "~16.0.0",
"@angular/compiler-cli": "^16.0.0",
"@types/jasmine": "~4.3.0",
"@types/node": "^18.7.0",
"jasmine-core": "~4.6.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.0.2"
}
}
*/
// C# Project file additions (.csproj)
/*
<PackageReference Include="MongoDB.Driver" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
*/
// Additional MongoDB indexes for better performance
/*
// In your MongoDB shell or through MongoDB Compass:
// Create indexes for better query performance
db.CacheDocument.createIndex({ "createdAt": -1 })
db.CacheDocument.createIndex({ "updatedAt": -1 })
db.CacheDocument.createIndex({ "data.name": 1 }) // If you commonly query by name
db.CacheDocument.createIndex({ "data.department": 1 }) // If you commonly query by department
// Create a compound index for common queries
db.CacheDocument.createIndex({
"data.department": 1,
"data.isActive": 1,
"createdAt": -1
})
*/