Ahmedtiger7 commited on
Commit
841722b
·
verified ·
1 Parent(s): b8814cd

Upload 23 files

Browse files
20260629155014_InitialCreate.Designer.cs ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // <auto-generated />
2
+ using System;
3
+ using Microsoft.EntityFrameworkCore;
4
+ using Microsoft.EntityFrameworkCore.Infrastructure;
5
+ using Microsoft.EntityFrameworkCore.Metadata;
6
+ using Microsoft.EntityFrameworkCore.Migrations;
7
+ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8
+ using QuickInvoiceSaaS.Data;
9
+
10
+ #nullable disable
11
+
12
+ namespace quickInvoiceSaaS.Migrations
13
+ {
14
+ [DbContext(typeof(ApplicationDbContext))]
15
+ [Migration("20260629155014_InitialCreate")]
16
+ partial class InitialCreate
17
+ {
18
+ /// <inheritdoc />
19
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
20
+ {
21
+ #pragma warning disable 612, 618
22
+ modelBuilder
23
+ .HasAnnotation("ProductVersion", "9.0.0")
24
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
25
+
26
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
27
+
28
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
29
+ {
30
+ b.Property<int>("Id")
31
+ .ValueGeneratedOnAdd()
32
+ .HasColumnType("int");
33
+
34
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
35
+
36
+ b.Property<string>("ClientEmail")
37
+ .HasColumnType("nvarchar(max)");
38
+
39
+ b.Property<string>("ClientName")
40
+ .IsRequired()
41
+ .HasMaxLength(150)
42
+ .HasColumnType("nvarchar(150)");
43
+
44
+ b.Property<string>("InvoiceNumber")
45
+ .IsRequired()
46
+ .HasMaxLength(50)
47
+ .HasColumnType("nvarchar(50)");
48
+
49
+ b.Property<DateTime>("IssueDate")
50
+ .HasColumnType("datetime2");
51
+
52
+ b.Property<string>("Status")
53
+ .IsRequired()
54
+ .HasColumnType("nvarchar(max)");
55
+
56
+ b.Property<string>("TenantId")
57
+ .IsRequired()
58
+ .HasColumnType("nvarchar(max)");
59
+
60
+ b.Property<decimal>("TotalAmount")
61
+ .HasColumnType("decimal(18,2)");
62
+
63
+ b.HasKey("Id");
64
+
65
+ b.ToTable("Invoices");
66
+ });
67
+
68
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
69
+ {
70
+ b.Property<int>("Id")
71
+ .ValueGeneratedOnAdd()
72
+ .HasColumnType("int");
73
+
74
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
75
+
76
+ b.Property<int>("InvoiceId")
77
+ .HasColumnType("int");
78
+
79
+ b.Property<string>("ProductName")
80
+ .IsRequired()
81
+ .HasMaxLength(250)
82
+ .HasColumnType("nvarchar(250)");
83
+
84
+ b.Property<int>("Quantity")
85
+ .HasColumnType("int");
86
+
87
+ b.Property<decimal>("UnitPrice")
88
+ .HasColumnType("decimal(18,2)");
89
+
90
+ b.HasKey("Id");
91
+
92
+ b.HasIndex("InvoiceId");
93
+
94
+ b.ToTable("InvoiceItems");
95
+ });
96
+
97
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Tenant", b =>
98
+ {
99
+ b.Property<string>("Id")
100
+ .HasColumnType("nvarchar(450)");
101
+
102
+ b.Property<string>("BusinessName")
103
+ .IsRequired()
104
+ .HasMaxLength(150)
105
+ .HasColumnType("nvarchar(150)");
106
+
107
+ b.Property<DateTime>("CreatedAt")
108
+ .HasColumnType("datetime2");
109
+
110
+ b.Property<string>("Currency")
111
+ .IsRequired()
112
+ .HasMaxLength(10)
113
+ .HasColumnType("nvarchar(10)");
114
+
115
+ b.Property<string>("LogoUrl")
116
+ .HasColumnType("nvarchar(max)");
117
+
118
+ b.HasKey("Id");
119
+
120
+ b.ToTable("Tenants");
121
+ });
122
+
123
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
124
+ {
125
+ b.HasOne("QuickInvoiceSaaS.Models.Invoice", "Invoice")
126
+ .WithMany("Items")
127
+ .HasForeignKey("InvoiceId")
128
+ .OnDelete(DeleteBehavior.Cascade)
129
+ .IsRequired();
130
+
131
+ b.Navigation("Invoice");
132
+ });
133
+
134
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
135
+ {
136
+ b.Navigation("Items");
137
+ });
138
+ #pragma warning restore 612, 618
139
+ }
140
+ }
141
+ }
20260629155014_InitialCreate.cs ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using Microsoft.EntityFrameworkCore.Migrations;
3
+
4
+ #nullable disable
5
+
6
+ namespace quickInvoiceSaaS.Migrations
7
+ {
8
+ /// <inheritdoc />
9
+ public partial class InitialCreate : Migration
10
+ {
11
+ /// <inheritdoc />
12
+ protected override void Up(MigrationBuilder migrationBuilder)
13
+ {
14
+ migrationBuilder.CreateTable(
15
+ name: "Invoices",
16
+ columns: table => new
17
+ {
18
+ Id = table.Column<int>(type: "int", nullable: false)
19
+ .Annotation("SqlServer:Identity", "1, 1"),
20
+ TenantId = table.Column<string>(type: "nvarchar(max)", nullable: false),
21
+ InvoiceNumber = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
22
+ ClientName = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
23
+ ClientEmail = table.Column<string>(type: "nvarchar(max)", nullable: true),
24
+ IssueDate = table.Column<DateTime>(type: "datetime2", nullable: false),
25
+ TotalAmount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
26
+ Status = table.Column<string>(type: "nvarchar(max)", nullable: false)
27
+ },
28
+ constraints: table =>
29
+ {
30
+ table.PrimaryKey("PK_Invoices", x => x.Id);
31
+ });
32
+
33
+ migrationBuilder.CreateTable(
34
+ name: "Tenants",
35
+ columns: table => new
36
+ {
37
+ Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
38
+ BusinessName = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
39
+ LogoUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
40
+ Currency = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
41
+ CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
42
+ },
43
+ constraints: table =>
44
+ {
45
+ table.PrimaryKey("PK_Tenants", x => x.Id);
46
+ });
47
+
48
+ migrationBuilder.CreateTable(
49
+ name: "InvoiceItems",
50
+ columns: table => new
51
+ {
52
+ Id = table.Column<int>(type: "int", nullable: false)
53
+ .Annotation("SqlServer:Identity", "1, 1"),
54
+ InvoiceId = table.Column<int>(type: "int", nullable: false),
55
+ ProductName = table.Column<string>(type: "nvarchar(250)", maxLength: 250, nullable: false),
56
+ Quantity = table.Column<int>(type: "int", nullable: false),
57
+ UnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
58
+ },
59
+ constraints: table =>
60
+ {
61
+ table.PrimaryKey("PK_InvoiceItems", x => x.Id);
62
+ table.ForeignKey(
63
+ name: "FK_InvoiceItems_Invoices_InvoiceId",
64
+ column: x => x.InvoiceId,
65
+ principalTable: "Invoices",
66
+ principalColumn: "Id",
67
+ onDelete: ReferentialAction.Cascade);
68
+ });
69
+
70
+ migrationBuilder.CreateIndex(
71
+ name: "IX_InvoiceItems_InvoiceId",
72
+ table: "InvoiceItems",
73
+ column: "InvoiceId");
74
+ }
75
+
76
+ /// <inheritdoc />
77
+ protected override void Down(MigrationBuilder migrationBuilder)
78
+ {
79
+ migrationBuilder.DropTable(
80
+ name: "InvoiceItems");
81
+
82
+ migrationBuilder.DropTable(
83
+ name: "Tenants");
84
+
85
+ migrationBuilder.DropTable(
86
+ name: "Invoices");
87
+ }
88
+ }
89
+ }
20260630110005_AddTenantIdToUsers.Designer.cs ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // <auto-generated />
2
+ using System;
3
+ using Microsoft.EntityFrameworkCore;
4
+ using Microsoft.EntityFrameworkCore.Infrastructure;
5
+ using Microsoft.EntityFrameworkCore.Metadata;
6
+ using Microsoft.EntityFrameworkCore.Migrations;
7
+ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8
+ using QuickInvoiceSaaS.Data;
9
+
10
+ #nullable disable
11
+
12
+ namespace quickInvoiceSaaS.Migrations
13
+ {
14
+ [DbContext(typeof(ApplicationDbContext))]
15
+ [Migration("20260630110005_AddTenantIdToUsers")]
16
+ partial class AddTenantIdToUsers
17
+ {
18
+ /// <inheritdoc />
19
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
20
+ {
21
+ #pragma warning disable 612, 618
22
+ modelBuilder
23
+ .HasAnnotation("ProductVersion", "9.0.0")
24
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
25
+
26
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
27
+
28
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
29
+ {
30
+ b.Property<string>("Id")
31
+ .HasColumnType("nvarchar(450)");
32
+
33
+ b.Property<string>("ConcurrencyStamp")
34
+ .IsConcurrencyToken()
35
+ .HasColumnType("nvarchar(max)");
36
+
37
+ b.Property<string>("Name")
38
+ .HasMaxLength(256)
39
+ .HasColumnType("nvarchar(256)");
40
+
41
+ b.Property<string>("NormalizedName")
42
+ .HasMaxLength(256)
43
+ .HasColumnType("nvarchar(256)");
44
+
45
+ b.HasKey("Id");
46
+
47
+ b.HasIndex("NormalizedName")
48
+ .IsUnique()
49
+ .HasDatabaseName("RoleNameIndex")
50
+ .HasFilter("[NormalizedName] IS NOT NULL");
51
+
52
+ b.ToTable("AspNetRoles", (string)null);
53
+ });
54
+
55
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
56
+ {
57
+ b.Property<int>("Id")
58
+ .ValueGeneratedOnAdd()
59
+ .HasColumnType("int");
60
+
61
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
62
+
63
+ b.Property<string>("ClaimType")
64
+ .HasColumnType("nvarchar(max)");
65
+
66
+ b.Property<string>("ClaimValue")
67
+ .HasColumnType("nvarchar(max)");
68
+
69
+ b.Property<string>("RoleId")
70
+ .IsRequired()
71
+ .HasColumnType("nvarchar(450)");
72
+
73
+ b.HasKey("Id");
74
+
75
+ b.HasIndex("RoleId");
76
+
77
+ b.ToTable("AspNetRoleClaims", (string)null);
78
+ });
79
+
80
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
81
+ {
82
+ b.Property<int>("Id")
83
+ .ValueGeneratedOnAdd()
84
+ .HasColumnType("int");
85
+
86
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
87
+
88
+ b.Property<string>("ClaimType")
89
+ .HasColumnType("nvarchar(max)");
90
+
91
+ b.Property<string>("ClaimValue")
92
+ .HasColumnType("nvarchar(max)");
93
+
94
+ b.Property<string>("UserId")
95
+ .IsRequired()
96
+ .HasColumnType("nvarchar(450)");
97
+
98
+ b.HasKey("Id");
99
+
100
+ b.HasIndex("UserId");
101
+
102
+ b.ToTable("AspNetUserClaims", (string)null);
103
+ });
104
+
105
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
106
+ {
107
+ b.Property<string>("LoginProvider")
108
+ .HasColumnType("nvarchar(450)");
109
+
110
+ b.Property<string>("ProviderKey")
111
+ .HasColumnType("nvarchar(450)");
112
+
113
+ b.Property<string>("ProviderDisplayName")
114
+ .HasColumnType("nvarchar(max)");
115
+
116
+ b.Property<string>("UserId")
117
+ .IsRequired()
118
+ .HasColumnType("nvarchar(450)");
119
+
120
+ b.HasKey("LoginProvider", "ProviderKey");
121
+
122
+ b.HasIndex("UserId");
123
+
124
+ b.ToTable("AspNetUserLogins", (string)null);
125
+ });
126
+
127
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
128
+ {
129
+ b.Property<string>("UserId")
130
+ .HasColumnType("nvarchar(450)");
131
+
132
+ b.Property<string>("RoleId")
133
+ .HasColumnType("nvarchar(450)");
134
+
135
+ b.HasKey("UserId", "RoleId");
136
+
137
+ b.HasIndex("RoleId");
138
+
139
+ b.ToTable("AspNetUserRoles", (string)null);
140
+ });
141
+
142
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
143
+ {
144
+ b.Property<string>("UserId")
145
+ .HasColumnType("nvarchar(450)");
146
+
147
+ b.Property<string>("LoginProvider")
148
+ .HasColumnType("nvarchar(450)");
149
+
150
+ b.Property<string>("Name")
151
+ .HasColumnType("nvarchar(450)");
152
+
153
+ b.Property<string>("Value")
154
+ .HasColumnType("nvarchar(max)");
155
+
156
+ b.HasKey("UserId", "LoginProvider", "Name");
157
+
158
+ b.ToTable("AspNetUserTokens", (string)null);
159
+ });
160
+
161
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.ApplicationUser", b =>
162
+ {
163
+ b.Property<string>("Id")
164
+ .HasColumnType("nvarchar(450)");
165
+
166
+ b.Property<int>("AccessFailedCount")
167
+ .HasColumnType("int");
168
+
169
+ b.Property<string>("ConcurrencyStamp")
170
+ .IsConcurrencyToken()
171
+ .HasColumnType("nvarchar(max)");
172
+
173
+ b.Property<string>("Email")
174
+ .HasMaxLength(256)
175
+ .HasColumnType("nvarchar(256)");
176
+
177
+ b.Property<bool>("EmailConfirmed")
178
+ .HasColumnType("bit");
179
+
180
+ b.Property<bool>("LockoutEnabled")
181
+ .HasColumnType("bit");
182
+
183
+ b.Property<DateTimeOffset?>("LockoutEnd")
184
+ .HasColumnType("datetimeoffset");
185
+
186
+ b.Property<string>("NormalizedEmail")
187
+ .HasMaxLength(256)
188
+ .HasColumnType("nvarchar(256)");
189
+
190
+ b.Property<string>("NormalizedUserName")
191
+ .HasMaxLength(256)
192
+ .HasColumnType("nvarchar(256)");
193
+
194
+ b.Property<string>("PasswordHash")
195
+ .HasColumnType("nvarchar(max)");
196
+
197
+ b.Property<string>("PhoneNumber")
198
+ .HasColumnType("nvarchar(max)");
199
+
200
+ b.Property<bool>("PhoneNumberConfirmed")
201
+ .HasColumnType("bit");
202
+
203
+ b.Property<string>("SecurityStamp")
204
+ .HasColumnType("nvarchar(max)");
205
+
206
+ b.Property<string>("TenantId")
207
+ .HasColumnType("nvarchar(max)")
208
+ .HasColumnName("TenantId");
209
+
210
+ b.Property<bool>("TwoFactorEnabled")
211
+ .HasColumnType("bit");
212
+
213
+ b.Property<string>("UserName")
214
+ .HasMaxLength(256)
215
+ .HasColumnType("nvarchar(256)");
216
+
217
+ b.HasKey("Id");
218
+
219
+ b.HasIndex("NormalizedEmail")
220
+ .HasDatabaseName("EmailIndex");
221
+
222
+ b.HasIndex("NormalizedUserName")
223
+ .IsUnique()
224
+ .HasDatabaseName("UserNameIndex")
225
+ .HasFilter("[NormalizedUserName] IS NOT NULL");
226
+
227
+ b.ToTable("AspNetUsers", (string)null);
228
+ });
229
+
230
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
231
+ {
232
+ b.Property<int>("Id")
233
+ .ValueGeneratedOnAdd()
234
+ .HasColumnType("int");
235
+
236
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
237
+
238
+ b.Property<string>("ClientEmail")
239
+ .HasColumnType("nvarchar(max)");
240
+
241
+ b.Property<string>("ClientName")
242
+ .IsRequired()
243
+ .HasMaxLength(150)
244
+ .HasColumnType("nvarchar(150)");
245
+
246
+ b.Property<string>("InvoiceNumber")
247
+ .IsRequired()
248
+ .HasMaxLength(50)
249
+ .HasColumnType("nvarchar(50)");
250
+
251
+ b.Property<DateTime>("IssueDate")
252
+ .HasColumnType("datetime2");
253
+
254
+ b.Property<string>("Status")
255
+ .IsRequired()
256
+ .HasColumnType("nvarchar(max)");
257
+
258
+ b.Property<string>("TenantId")
259
+ .IsRequired()
260
+ .HasColumnType("nvarchar(max)")
261
+ .HasColumnName("TenantId");
262
+
263
+ b.Property<decimal>("TotalAmount")
264
+ .HasColumnType("decimal(18,2)");
265
+
266
+ b.HasKey("Id");
267
+
268
+ b.ToTable("Invoices", (string)null);
269
+ });
270
+
271
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
272
+ {
273
+ b.Property<int>("Id")
274
+ .ValueGeneratedOnAdd()
275
+ .HasColumnType("int");
276
+
277
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
278
+
279
+ b.Property<int>("InvoiceId")
280
+ .HasColumnType("int");
281
+
282
+ b.Property<string>("ProductName")
283
+ .IsRequired()
284
+ .HasMaxLength(250)
285
+ .HasColumnType("nvarchar(250)");
286
+
287
+ b.Property<int>("Quantity")
288
+ .HasColumnType("int");
289
+
290
+ b.Property<decimal>("UnitPrice")
291
+ .HasColumnType("decimal(18,2)");
292
+
293
+ b.HasKey("Id");
294
+
295
+ b.HasIndex("InvoiceId");
296
+
297
+ b.ToTable("InvoiceItem");
298
+ });
299
+
300
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
301
+ {
302
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
303
+ .WithMany()
304
+ .HasForeignKey("RoleId")
305
+ .OnDelete(DeleteBehavior.Cascade)
306
+ .IsRequired();
307
+ });
308
+
309
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
310
+ {
311
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
312
+ .WithMany()
313
+ .HasForeignKey("UserId")
314
+ .OnDelete(DeleteBehavior.Cascade)
315
+ .IsRequired();
316
+ });
317
+
318
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
319
+ {
320
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
321
+ .WithMany()
322
+ .HasForeignKey("UserId")
323
+ .OnDelete(DeleteBehavior.Cascade)
324
+ .IsRequired();
325
+ });
326
+
327
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
328
+ {
329
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
330
+ .WithMany()
331
+ .HasForeignKey("RoleId")
332
+ .OnDelete(DeleteBehavior.Cascade)
333
+ .IsRequired();
334
+
335
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
336
+ .WithMany()
337
+ .HasForeignKey("UserId")
338
+ .OnDelete(DeleteBehavior.Cascade)
339
+ .IsRequired();
340
+ });
341
+
342
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
343
+ {
344
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
345
+ .WithMany()
346
+ .HasForeignKey("UserId")
347
+ .OnDelete(DeleteBehavior.Cascade)
348
+ .IsRequired();
349
+ });
350
+
351
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
352
+ {
353
+ b.HasOne("QuickInvoiceSaaS.Models.Invoice", "Invoice")
354
+ .WithMany("Items")
355
+ .HasForeignKey("InvoiceId")
356
+ .OnDelete(DeleteBehavior.Cascade)
357
+ .IsRequired();
358
+
359
+ b.Navigation("Invoice");
360
+ });
361
+
362
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
363
+ {
364
+ b.Navigation("Items");
365
+ });
366
+ #pragma warning restore 612, 618
367
+ }
368
+ }
369
+ }
20260630110005_AddTenantIdToUsers.cs ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using Microsoft.EntityFrameworkCore.Migrations;
3
+
4
+ #nullable disable
5
+
6
+ namespace quickInvoiceSaaS.Migrations
7
+ {
8
+ /// <inheritdoc />
9
+ public partial class AddTenantIdToUsers : Migration
10
+ {
11
+ /// <inheritdoc />
12
+ protected override void Up(MigrationBuilder migrationBuilder)
13
+ {
14
+ migrationBuilder.DropForeignKey(
15
+ name: "FK_InvoiceItems_Invoices_InvoiceId",
16
+ table: "InvoiceItems");
17
+
18
+ migrationBuilder.DropTable(
19
+ name: "Tenants");
20
+
21
+ migrationBuilder.DropPrimaryKey(
22
+ name: "PK_InvoiceItems",
23
+ table: "InvoiceItems");
24
+
25
+ migrationBuilder.RenameTable(
26
+ name: "InvoiceItems",
27
+ newName: "InvoiceItem");
28
+
29
+ migrationBuilder.RenameIndex(
30
+ name: "IX_InvoiceItems_InvoiceId",
31
+ table: "InvoiceItem",
32
+ newName: "IX_InvoiceItem_InvoiceId");
33
+
34
+ migrationBuilder.AddPrimaryKey(
35
+ name: "PK_InvoiceItem",
36
+ table: "InvoiceItem",
37
+ column: "Id");
38
+
39
+ migrationBuilder.CreateTable(
40
+ name: "AspNetRoles",
41
+ columns: table => new
42
+ {
43
+ Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
44
+ Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
45
+ NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
46
+ ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true)
47
+ },
48
+ constraints: table =>
49
+ {
50
+ table.PrimaryKey("PK_AspNetRoles", x => x.Id);
51
+ });
52
+
53
+ migrationBuilder.CreateTable(
54
+ name: "AspNetUsers",
55
+ columns: table => new
56
+ {
57
+ Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
58
+ TenantId = table.Column<string>(type: "nvarchar(max)", nullable: true),
59
+ UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
60
+ NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
61
+ Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
62
+ NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
63
+ EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
64
+ PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
65
+ SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
66
+ ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
67
+ PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
68
+ PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
69
+ TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
70
+ LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
71
+ LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
72
+ AccessFailedCount = table.Column<int>(type: "int", nullable: false)
73
+ },
74
+ constraints: table =>
75
+ {
76
+ table.PrimaryKey("PK_AspNetUsers", x => x.Id);
77
+ });
78
+
79
+ migrationBuilder.CreateTable(
80
+ name: "AspNetRoleClaims",
81
+ columns: table => new
82
+ {
83
+ Id = table.Column<int>(type: "int", nullable: false)
84
+ .Annotation("SqlServer:Identity", "1, 1"),
85
+ RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false),
86
+ ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
87
+ ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
88
+ },
89
+ constraints: table =>
90
+ {
91
+ table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
92
+ table.ForeignKey(
93
+ name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
94
+ column: x => x.RoleId,
95
+ principalTable: "AspNetRoles",
96
+ principalColumn: "Id",
97
+ onDelete: ReferentialAction.Cascade);
98
+ });
99
+
100
+ migrationBuilder.CreateTable(
101
+ name: "AspNetUserClaims",
102
+ columns: table => new
103
+ {
104
+ Id = table.Column<int>(type: "int", nullable: false)
105
+ .Annotation("SqlServer:Identity", "1, 1"),
106
+ UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
107
+ ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
108
+ ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
109
+ },
110
+ constraints: table =>
111
+ {
112
+ table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
113
+ table.ForeignKey(
114
+ name: "FK_AspNetUserClaims_AspNetUsers_UserId",
115
+ column: x => x.UserId,
116
+ principalTable: "AspNetUsers",
117
+ principalColumn: "Id",
118
+ onDelete: ReferentialAction.Cascade);
119
+ });
120
+
121
+ migrationBuilder.CreateTable(
122
+ name: "AspNetUserLogins",
123
+ columns: table => new
124
+ {
125
+ LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
126
+ ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
127
+ ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
128
+ UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
129
+ },
130
+ constraints: table =>
131
+ {
132
+ table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
133
+ table.ForeignKey(
134
+ name: "FK_AspNetUserLogins_AspNetUsers_UserId",
135
+ column: x => x.UserId,
136
+ principalTable: "AspNetUsers",
137
+ principalColumn: "Id",
138
+ onDelete: ReferentialAction.Cascade);
139
+ });
140
+
141
+ migrationBuilder.CreateTable(
142
+ name: "AspNetUserRoles",
143
+ columns: table => new
144
+ {
145
+ UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
146
+ RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false)
147
+ },
148
+ constraints: table =>
149
+ {
150
+ table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
151
+ table.ForeignKey(
152
+ name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
153
+ column: x => x.RoleId,
154
+ principalTable: "AspNetRoles",
155
+ principalColumn: "Id",
156
+ onDelete: ReferentialAction.Cascade);
157
+ table.ForeignKey(
158
+ name: "FK_AspNetUserRoles_AspNetUsers_UserId",
159
+ column: x => x.UserId,
160
+ principalTable: "AspNetUsers",
161
+ principalColumn: "Id",
162
+ onDelete: ReferentialAction.Cascade);
163
+ });
164
+
165
+ migrationBuilder.CreateTable(
166
+ name: "AspNetUserTokens",
167
+ columns: table => new
168
+ {
169
+ UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
170
+ LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
171
+ Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
172
+ Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
173
+ },
174
+ constraints: table =>
175
+ {
176
+ table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
177
+ table.ForeignKey(
178
+ name: "FK_AspNetUserTokens_AspNetUsers_UserId",
179
+ column: x => x.UserId,
180
+ principalTable: "AspNetUsers",
181
+ principalColumn: "Id",
182
+ onDelete: ReferentialAction.Cascade);
183
+ });
184
+
185
+ migrationBuilder.CreateIndex(
186
+ name: "IX_AspNetRoleClaims_RoleId",
187
+ table: "AspNetRoleClaims",
188
+ column: "RoleId");
189
+
190
+ migrationBuilder.CreateIndex(
191
+ name: "RoleNameIndex",
192
+ table: "AspNetRoles",
193
+ column: "NormalizedName",
194
+ unique: true,
195
+ filter: "[NormalizedName] IS NOT NULL");
196
+
197
+ migrationBuilder.CreateIndex(
198
+ name: "IX_AspNetUserClaims_UserId",
199
+ table: "AspNetUserClaims",
200
+ column: "UserId");
201
+
202
+ migrationBuilder.CreateIndex(
203
+ name: "IX_AspNetUserLogins_UserId",
204
+ table: "AspNetUserLogins",
205
+ column: "UserId");
206
+
207
+ migrationBuilder.CreateIndex(
208
+ name: "IX_AspNetUserRoles_RoleId",
209
+ table: "AspNetUserRoles",
210
+ column: "RoleId");
211
+
212
+ migrationBuilder.CreateIndex(
213
+ name: "EmailIndex",
214
+ table: "AspNetUsers",
215
+ column: "NormalizedEmail");
216
+
217
+ migrationBuilder.CreateIndex(
218
+ name: "UserNameIndex",
219
+ table: "AspNetUsers",
220
+ column: "NormalizedUserName",
221
+ unique: true,
222
+ filter: "[NormalizedUserName] IS NOT NULL");
223
+
224
+ migrationBuilder.AddForeignKey(
225
+ name: "FK_InvoiceItem_Invoices_InvoiceId",
226
+ table: "InvoiceItem",
227
+ column: "InvoiceId",
228
+ principalTable: "Invoices",
229
+ principalColumn: "Id",
230
+ onDelete: ReferentialAction.Cascade);
231
+ }
232
+
233
+ /// <inheritdoc />
234
+ protected override void Down(MigrationBuilder migrationBuilder)
235
+ {
236
+ migrationBuilder.DropForeignKey(
237
+ name: "FK_InvoiceItem_Invoices_InvoiceId",
238
+ table: "InvoiceItem");
239
+
240
+ migrationBuilder.DropTable(
241
+ name: "AspNetRoleClaims");
242
+
243
+ migrationBuilder.DropTable(
244
+ name: "AspNetUserClaims");
245
+
246
+ migrationBuilder.DropTable(
247
+ name: "AspNetUserLogins");
248
+
249
+ migrationBuilder.DropTable(
250
+ name: "AspNetUserRoles");
251
+
252
+ migrationBuilder.DropTable(
253
+ name: "AspNetUserTokens");
254
+
255
+ migrationBuilder.DropTable(
256
+ name: "AspNetRoles");
257
+
258
+ migrationBuilder.DropTable(
259
+ name: "AspNetUsers");
260
+
261
+ migrationBuilder.DropPrimaryKey(
262
+ name: "PK_InvoiceItem",
263
+ table: "InvoiceItem");
264
+
265
+ migrationBuilder.RenameTable(
266
+ name: "InvoiceItem",
267
+ newName: "InvoiceItems");
268
+
269
+ migrationBuilder.RenameIndex(
270
+ name: "IX_InvoiceItem_InvoiceId",
271
+ table: "InvoiceItems",
272
+ newName: "IX_InvoiceItems_InvoiceId");
273
+
274
+ migrationBuilder.AddPrimaryKey(
275
+ name: "PK_InvoiceItems",
276
+ table: "InvoiceItems",
277
+ column: "Id");
278
+
279
+ migrationBuilder.CreateTable(
280
+ name: "Tenants",
281
+ columns: table => new
282
+ {
283
+ Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
284
+ BusinessName = table.Column<string>(type: "nvarchar(150)", maxLength: 150, nullable: false),
285
+ CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
286
+ Currency = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
287
+ LogoUrl = table.Column<string>(type: "nvarchar(max)", nullable: true)
288
+ },
289
+ constraints: table =>
290
+ {
291
+ table.PrimaryKey("PK_Tenants", x => x.Id);
292
+ });
293
+
294
+ migrationBuilder.AddForeignKey(
295
+ name: "FK_InvoiceItems_Invoices_InvoiceId",
296
+ table: "InvoiceItems",
297
+ column: "InvoiceId",
298
+ principalTable: "Invoices",
299
+ principalColumn: "Id",
300
+ onDelete: ReferentialAction.Cascade);
301
+ }
302
+ }
303
+ }
20260701003932_AddSubscriptionPlanToUsers.Designer.cs ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // <auto-generated />
2
+ using System;
3
+ using Microsoft.EntityFrameworkCore;
4
+ using Microsoft.EntityFrameworkCore.Infrastructure;
5
+ using Microsoft.EntityFrameworkCore.Metadata;
6
+ using Microsoft.EntityFrameworkCore.Migrations;
7
+ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8
+ using QuickInvoiceSaaS.Data;
9
+
10
+ #nullable disable
11
+
12
+ namespace quickInvoiceSaaS.Migrations
13
+ {
14
+ [DbContext(typeof(ApplicationDbContext))]
15
+ [Migration("20260701003932_AddSubscriptionPlanToUsers")]
16
+ partial class AddSubscriptionPlanToUsers
17
+ {
18
+ /// <inheritdoc />
19
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
20
+ {
21
+ #pragma warning disable 612, 618
22
+ modelBuilder
23
+ .HasAnnotation("ProductVersion", "9.0.0")
24
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
25
+
26
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
27
+
28
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
29
+ {
30
+ b.Property<string>("Id")
31
+ .HasColumnType("nvarchar(450)");
32
+
33
+ b.Property<string>("ConcurrencyStamp")
34
+ .IsConcurrencyToken()
35
+ .HasColumnType("nvarchar(max)");
36
+
37
+ b.Property<string>("Name")
38
+ .HasMaxLength(256)
39
+ .HasColumnType("nvarchar(256)");
40
+
41
+ b.Property<string>("NormalizedName")
42
+ .HasMaxLength(256)
43
+ .HasColumnType("nvarchar(256)");
44
+
45
+ b.HasKey("Id");
46
+
47
+ b.HasIndex("NormalizedName")
48
+ .IsUnique()
49
+ .HasDatabaseName("RoleNameIndex")
50
+ .HasFilter("[NormalizedName] IS NOT NULL");
51
+
52
+ b.ToTable("AspNetRoles", (string)null);
53
+ });
54
+
55
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
56
+ {
57
+ b.Property<int>("Id")
58
+ .ValueGeneratedOnAdd()
59
+ .HasColumnType("int");
60
+
61
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
62
+
63
+ b.Property<string>("ClaimType")
64
+ .HasColumnType("nvarchar(max)");
65
+
66
+ b.Property<string>("ClaimValue")
67
+ .HasColumnType("nvarchar(max)");
68
+
69
+ b.Property<string>("RoleId")
70
+ .IsRequired()
71
+ .HasColumnType("nvarchar(450)");
72
+
73
+ b.HasKey("Id");
74
+
75
+ b.HasIndex("RoleId");
76
+
77
+ b.ToTable("AspNetRoleClaims", (string)null);
78
+ });
79
+
80
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
81
+ {
82
+ b.Property<int>("Id")
83
+ .ValueGeneratedOnAdd()
84
+ .HasColumnType("int");
85
+
86
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
87
+
88
+ b.Property<string>("ClaimType")
89
+ .HasColumnType("nvarchar(max)");
90
+
91
+ b.Property<string>("ClaimValue")
92
+ .HasColumnType("nvarchar(max)");
93
+
94
+ b.Property<string>("UserId")
95
+ .IsRequired()
96
+ .HasColumnType("nvarchar(450)");
97
+
98
+ b.HasKey("Id");
99
+
100
+ b.HasIndex("UserId");
101
+
102
+ b.ToTable("AspNetUserClaims", (string)null);
103
+ });
104
+
105
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
106
+ {
107
+ b.Property<string>("LoginProvider")
108
+ .HasColumnType("nvarchar(450)");
109
+
110
+ b.Property<string>("ProviderKey")
111
+ .HasColumnType("nvarchar(450)");
112
+
113
+ b.Property<string>("ProviderDisplayName")
114
+ .HasColumnType("nvarchar(max)");
115
+
116
+ b.Property<string>("UserId")
117
+ .IsRequired()
118
+ .HasColumnType("nvarchar(450)");
119
+
120
+ b.HasKey("LoginProvider", "ProviderKey");
121
+
122
+ b.HasIndex("UserId");
123
+
124
+ b.ToTable("AspNetUserLogins", (string)null);
125
+ });
126
+
127
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
128
+ {
129
+ b.Property<string>("UserId")
130
+ .HasColumnType("nvarchar(450)");
131
+
132
+ b.Property<string>("RoleId")
133
+ .HasColumnType("nvarchar(450)");
134
+
135
+ b.HasKey("UserId", "RoleId");
136
+
137
+ b.HasIndex("RoleId");
138
+
139
+ b.ToTable("AspNetUserRoles", (string)null);
140
+ });
141
+
142
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
143
+ {
144
+ b.Property<string>("UserId")
145
+ .HasColumnType("nvarchar(450)");
146
+
147
+ b.Property<string>("LoginProvider")
148
+ .HasColumnType("nvarchar(450)");
149
+
150
+ b.Property<string>("Name")
151
+ .HasColumnType("nvarchar(450)");
152
+
153
+ b.Property<string>("Value")
154
+ .HasColumnType("nvarchar(max)");
155
+
156
+ b.HasKey("UserId", "LoginProvider", "Name");
157
+
158
+ b.ToTable("AspNetUserTokens", (string)null);
159
+ });
160
+
161
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.ApplicationUser", b =>
162
+ {
163
+ b.Property<string>("Id")
164
+ .HasColumnType("nvarchar(450)");
165
+
166
+ b.Property<int>("AccessFailedCount")
167
+ .HasColumnType("int");
168
+
169
+ b.Property<string>("ConcurrencyStamp")
170
+ .IsConcurrencyToken()
171
+ .HasColumnType("nvarchar(max)");
172
+
173
+ b.Property<string>("Email")
174
+ .HasMaxLength(256)
175
+ .HasColumnType("nvarchar(256)");
176
+
177
+ b.Property<bool>("EmailConfirmed")
178
+ .HasColumnType("bit");
179
+
180
+ b.Property<bool>("LockoutEnabled")
181
+ .HasColumnType("bit");
182
+
183
+ b.Property<DateTimeOffset?>("LockoutEnd")
184
+ .HasColumnType("datetimeoffset");
185
+
186
+ b.Property<string>("NormalizedEmail")
187
+ .HasMaxLength(256)
188
+ .HasColumnType("nvarchar(256)");
189
+
190
+ b.Property<string>("NormalizedUserName")
191
+ .HasMaxLength(256)
192
+ .HasColumnType("nvarchar(256)");
193
+
194
+ b.Property<string>("PasswordHash")
195
+ .HasColumnType("nvarchar(max)");
196
+
197
+ b.Property<string>("PhoneNumber")
198
+ .HasColumnType("nvarchar(max)");
199
+
200
+ b.Property<bool>("PhoneNumberConfirmed")
201
+ .HasColumnType("bit");
202
+
203
+ b.Property<string>("SecurityStamp")
204
+ .HasColumnType("nvarchar(max)");
205
+
206
+ b.Property<string>("SubscriptionPlan")
207
+ .IsRequired()
208
+ .HasColumnType("nvarchar(max)");
209
+
210
+ b.Property<string>("TenantId")
211
+ .HasColumnType("nvarchar(max)")
212
+ .HasColumnName("TenantId");
213
+
214
+ b.Property<bool>("TwoFactorEnabled")
215
+ .HasColumnType("bit");
216
+
217
+ b.Property<string>("UserName")
218
+ .HasMaxLength(256)
219
+ .HasColumnType("nvarchar(256)");
220
+
221
+ b.HasKey("Id");
222
+
223
+ b.HasIndex("NormalizedEmail")
224
+ .HasDatabaseName("EmailIndex");
225
+
226
+ b.HasIndex("NormalizedUserName")
227
+ .IsUnique()
228
+ .HasDatabaseName("UserNameIndex")
229
+ .HasFilter("[NormalizedUserName] IS NOT NULL");
230
+
231
+ b.ToTable("AspNetUsers", (string)null);
232
+ });
233
+
234
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
235
+ {
236
+ b.Property<int>("Id")
237
+ .ValueGeneratedOnAdd()
238
+ .HasColumnType("int");
239
+
240
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
241
+
242
+ b.Property<string>("ClientEmail")
243
+ .HasColumnType("nvarchar(max)");
244
+
245
+ b.Property<string>("ClientName")
246
+ .IsRequired()
247
+ .HasMaxLength(150)
248
+ .HasColumnType("nvarchar(150)");
249
+
250
+ b.Property<string>("InvoiceNumber")
251
+ .IsRequired()
252
+ .HasMaxLength(50)
253
+ .HasColumnType("nvarchar(50)");
254
+
255
+ b.Property<DateTime>("IssueDate")
256
+ .HasColumnType("datetime2");
257
+
258
+ b.Property<string>("Status")
259
+ .IsRequired()
260
+ .HasColumnType("nvarchar(max)");
261
+
262
+ b.Property<string>("TenantId")
263
+ .IsRequired()
264
+ .HasColumnType("nvarchar(max)")
265
+ .HasColumnName("TenantId");
266
+
267
+ b.Property<decimal>("TotalAmount")
268
+ .HasColumnType("decimal(18,2)");
269
+
270
+ b.HasKey("Id");
271
+
272
+ b.ToTable("Invoices", (string)null);
273
+ });
274
+
275
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
276
+ {
277
+ b.Property<int>("Id")
278
+ .ValueGeneratedOnAdd()
279
+ .HasColumnType("int");
280
+
281
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
282
+
283
+ b.Property<int>("InvoiceId")
284
+ .HasColumnType("int");
285
+
286
+ b.Property<string>("ProductName")
287
+ .IsRequired()
288
+ .HasMaxLength(250)
289
+ .HasColumnType("nvarchar(250)");
290
+
291
+ b.Property<int>("Quantity")
292
+ .HasColumnType("int");
293
+
294
+ b.Property<decimal>("UnitPrice")
295
+ .HasColumnType("decimal(18,2)");
296
+
297
+ b.HasKey("Id");
298
+
299
+ b.HasIndex("InvoiceId");
300
+
301
+ b.ToTable("InvoiceItem");
302
+ });
303
+
304
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
305
+ {
306
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
307
+ .WithMany()
308
+ .HasForeignKey("RoleId")
309
+ .OnDelete(DeleteBehavior.Cascade)
310
+ .IsRequired();
311
+ });
312
+
313
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
314
+ {
315
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
316
+ .WithMany()
317
+ .HasForeignKey("UserId")
318
+ .OnDelete(DeleteBehavior.Cascade)
319
+ .IsRequired();
320
+ });
321
+
322
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
323
+ {
324
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
325
+ .WithMany()
326
+ .HasForeignKey("UserId")
327
+ .OnDelete(DeleteBehavior.Cascade)
328
+ .IsRequired();
329
+ });
330
+
331
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
332
+ {
333
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
334
+ .WithMany()
335
+ .HasForeignKey("RoleId")
336
+ .OnDelete(DeleteBehavior.Cascade)
337
+ .IsRequired();
338
+
339
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
340
+ .WithMany()
341
+ .HasForeignKey("UserId")
342
+ .OnDelete(DeleteBehavior.Cascade)
343
+ .IsRequired();
344
+ });
345
+
346
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
347
+ {
348
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
349
+ .WithMany()
350
+ .HasForeignKey("UserId")
351
+ .OnDelete(DeleteBehavior.Cascade)
352
+ .IsRequired();
353
+ });
354
+
355
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
356
+ {
357
+ b.HasOne("QuickInvoiceSaaS.Models.Invoice", "Invoice")
358
+ .WithMany("Items")
359
+ .HasForeignKey("InvoiceId")
360
+ .OnDelete(DeleteBehavior.Cascade)
361
+ .IsRequired();
362
+
363
+ b.Navigation("Invoice");
364
+ });
365
+
366
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
367
+ {
368
+ b.Navigation("Items");
369
+ });
370
+ #pragma warning restore 612, 618
371
+ }
372
+ }
373
+ }
20260701003932_AddSubscriptionPlanToUsers.cs ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+ #nullable disable
4
+
5
+ namespace quickInvoiceSaaS.Migrations
6
+ {
7
+ /// <inheritdoc />
8
+ public partial class AddSubscriptionPlanToUsers : Migration
9
+ {
10
+ /// <inheritdoc />
11
+ protected override void Up(MigrationBuilder migrationBuilder)
12
+ {
13
+ migrationBuilder.AddColumn<string>(
14
+ name: "SubscriptionPlan",
15
+ table: "AspNetUsers",
16
+ type: "nvarchar(max)",
17
+ nullable: false,
18
+ defaultValue: "");
19
+ }
20
+
21
+ /// <inheritdoc />
22
+ protected override void Down(MigrationBuilder migrationBuilder)
23
+ {
24
+ migrationBuilder.DropColumn(
25
+ name: "SubscriptionPlan",
26
+ table: "AspNetUsers");
27
+ }
28
+ }
29
+ }
AccountController.cs ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.AspNetCore.Identity;
2
+ using Microsoft.AspNetCore.Mvc;
3
+ using QuickInvoiceSaaS.Models;
4
+
5
+ namespace QuickInvoiceSaaS.Controllers
6
+ {
7
+ public class AccountController : Controller
8
+ {
9
+ private readonly UserManager<ApplicationUser> _userManager;
10
+ private readonly SignInManager<ApplicationUser> _signInManager;
11
+
12
+ public AccountController(UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
13
+ {
14
+ _userManager = userManager;
15
+ _signInManager = signInManager;
16
+ }
17
+
18
+ // --- شاشة إنشاء حساب جديد ---
19
+ [HttpGet]
20
+ public IActionResult Register() => View();
21
+
22
+ [HttpPost]
23
+ public async Task<IActionResult> Register(RegisterViewModel model)
24
+ {
25
+ if (ModelState.IsValid)
26
+ {
27
+ var user = new ApplicationUser
28
+ {
29
+ UserName = model.Email,
30
+ Email = model.Email,
31
+ TenantId = model.TenantId,// ربط المستخدم بالشركة هنا 🎯
32
+ SubscriptionPlan = model.SubscriptionPlan // 🔥 حفظ الباقة هنا
33
+ };
34
+
35
+ var result = await _userManager.CreateAsync(user, model.Password);
36
+ if (result.Succeeded)
37
+ {
38
+ await _signInManager.SignInAsync(user, isPersistent: false);
39
+ return RedirectToAction("Index", "InvoicesWeb");
40
+ }
41
+
42
+ foreach (var error in result.Errors)
43
+ {
44
+ ModelState.AddModelError("", error.Description);
45
+ }
46
+ }
47
+ return View(model);
48
+ }
49
+
50
+ // --- شاشة تسجيل الدخول ---
51
+ [HttpGet]
52
+ public IActionResult Login() => View();
53
+
54
+ [HttpPost]
55
+ public async Task<IActionResult> Login(LoginViewModel model)
56
+ {
57
+ if (ModelState.IsValid)
58
+ {
59
+ var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
60
+ if (result.Succeeded)
61
+ {
62
+ return RedirectToAction("Index", "InvoicesWeb");
63
+ }
64
+ ModelState.AddModelError("", "محاولة دخول غير صحيحة، تأكد من البيانات.");
65
+ }
66
+ return View(model);
67
+ }
68
+ [HttpPost]
69
+ [ValidateAntiForgeryToken]
70
+ public async Task<IActionResult> UpgradeToPremium()
71
+ {
72
+ // 1. جلب المستخدم الحالي المسجل دخوله
73
+ var user = await _userManager.GetUserAsync(User);
74
+ if (user == null) return Challenge();
75
+
76
+ // 2. تغيير خطته إلى الباقة الممتازة
77
+ user.SubscriptionPlan = "Premium";
78
+
79
+ // 3. حفظ التعديل في قاعدة البيانات
80
+ var result = await _userManager.UpdateAsync(user);
81
+
82
+ // 4. إعادة توجيهه إلى صفحة الفواتير مجدداً بعد الترقية
83
+ return RedirectToAction("Index", "InvoicesWeb");
84
+ }
85
+
86
+ // --- تسجيل الخروج ---
87
+ [HttpPost]
88
+ public async Task<IActionResult> Logout()
89
+ {
90
+ await _signInManager.SignOutAsync();
91
+ return RedirectToAction("Login", "Account");
92
+ }
93
+ }
94
+ }
ApplicationDbContext.cs ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
2
+ using Microsoft.EntityFrameworkCore;
3
+ using QuickInvoiceSaaS.Models;
4
+
5
+ namespace QuickInvoiceSaaS.Data
6
+ {
7
+ // يرث من IdentityDbContext المخصص لـ ApplicationUser لإدارة هويات مستخدمي الشركات
8
+ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
9
+ {
10
+ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
11
+ : base(options)
12
+ {
13
+ }
14
+
15
+ // جدول الفواتير الرئيسي
16
+ public DbSet<Invoice> Invoices { get; set; }
17
+
18
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
19
+ {
20
+ // ضروري جداً لتأسيس جداول الـ Identity (المستخدمين، الأدوار، الصلاحيات)
21
+ base.OnModelCreating(modelBuilder);
22
+
23
+ // تأكيد ربط اسم العمود بالكابيتال وتثبيته في قاعدة البيانات لمنع أي تعارض
24
+ modelBuilder.Entity<Invoice>(entity =>
25
+ {
26
+ entity.ToTable("Invoices");
27
+ entity.Property(e => e.TenantId)
28
+ .HasColumnName("TenantId")
29
+ .IsRequired(); // يمكن إلغاؤها إذا كنت تسمح بفواتير بدون شركة
30
+ });
31
+
32
+ modelBuilder.Entity<ApplicationUser>(entity =>
33
+ {
34
+ entity.Property(e => e.TenantId)
35
+ .HasColumnName("TenantId")
36
+ .IsRequired(false); // نجعله اختياري للمشرفين العامين (Admin) مثلاً
37
+ });
38
+ }
39
+ }
40
+ }
ApplicationDbContextModelSnapshot.cs ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // <auto-generated />
2
+ using System;
3
+ using Microsoft.EntityFrameworkCore;
4
+ using Microsoft.EntityFrameworkCore.Infrastructure;
5
+ using Microsoft.EntityFrameworkCore.Metadata;
6
+ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7
+ using QuickInvoiceSaaS.Data;
8
+
9
+ #nullable disable
10
+
11
+ namespace quickInvoiceSaaS.Migrations
12
+ {
13
+ [DbContext(typeof(ApplicationDbContext))]
14
+ partial class ApplicationDbContextModelSnapshot : ModelSnapshot
15
+ {
16
+ protected override void BuildModel(ModelBuilder modelBuilder)
17
+ {
18
+ #pragma warning disable 612, 618
19
+ modelBuilder
20
+ .HasAnnotation("ProductVersion", "9.0.0")
21
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
22
+
23
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
24
+
25
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
26
+ {
27
+ b.Property<string>("Id")
28
+ .HasColumnType("nvarchar(450)");
29
+
30
+ b.Property<string>("ConcurrencyStamp")
31
+ .IsConcurrencyToken()
32
+ .HasColumnType("nvarchar(max)");
33
+
34
+ b.Property<string>("Name")
35
+ .HasMaxLength(256)
36
+ .HasColumnType("nvarchar(256)");
37
+
38
+ b.Property<string>("NormalizedName")
39
+ .HasMaxLength(256)
40
+ .HasColumnType("nvarchar(256)");
41
+
42
+ b.HasKey("Id");
43
+
44
+ b.HasIndex("NormalizedName")
45
+ .IsUnique()
46
+ .HasDatabaseName("RoleNameIndex")
47
+ .HasFilter("[NormalizedName] IS NOT NULL");
48
+
49
+ b.ToTable("AspNetRoles", (string)null);
50
+ });
51
+
52
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
53
+ {
54
+ b.Property<int>("Id")
55
+ .ValueGeneratedOnAdd()
56
+ .HasColumnType("int");
57
+
58
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
59
+
60
+ b.Property<string>("ClaimType")
61
+ .HasColumnType("nvarchar(max)");
62
+
63
+ b.Property<string>("ClaimValue")
64
+ .HasColumnType("nvarchar(max)");
65
+
66
+ b.Property<string>("RoleId")
67
+ .IsRequired()
68
+ .HasColumnType("nvarchar(450)");
69
+
70
+ b.HasKey("Id");
71
+
72
+ b.HasIndex("RoleId");
73
+
74
+ b.ToTable("AspNetRoleClaims", (string)null);
75
+ });
76
+
77
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
78
+ {
79
+ b.Property<int>("Id")
80
+ .ValueGeneratedOnAdd()
81
+ .HasColumnType("int");
82
+
83
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
84
+
85
+ b.Property<string>("ClaimType")
86
+ .HasColumnType("nvarchar(max)");
87
+
88
+ b.Property<string>("ClaimValue")
89
+ .HasColumnType("nvarchar(max)");
90
+
91
+ b.Property<string>("UserId")
92
+ .IsRequired()
93
+ .HasColumnType("nvarchar(450)");
94
+
95
+ b.HasKey("Id");
96
+
97
+ b.HasIndex("UserId");
98
+
99
+ b.ToTable("AspNetUserClaims", (string)null);
100
+ });
101
+
102
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
103
+ {
104
+ b.Property<string>("LoginProvider")
105
+ .HasColumnType("nvarchar(450)");
106
+
107
+ b.Property<string>("ProviderKey")
108
+ .HasColumnType("nvarchar(450)");
109
+
110
+ b.Property<string>("ProviderDisplayName")
111
+ .HasColumnType("nvarchar(max)");
112
+
113
+ b.Property<string>("UserId")
114
+ .IsRequired()
115
+ .HasColumnType("nvarchar(450)");
116
+
117
+ b.HasKey("LoginProvider", "ProviderKey");
118
+
119
+ b.HasIndex("UserId");
120
+
121
+ b.ToTable("AspNetUserLogins", (string)null);
122
+ });
123
+
124
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
125
+ {
126
+ b.Property<string>("UserId")
127
+ .HasColumnType("nvarchar(450)");
128
+
129
+ b.Property<string>("RoleId")
130
+ .HasColumnType("nvarchar(450)");
131
+
132
+ b.HasKey("UserId", "RoleId");
133
+
134
+ b.HasIndex("RoleId");
135
+
136
+ b.ToTable("AspNetUserRoles", (string)null);
137
+ });
138
+
139
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
140
+ {
141
+ b.Property<string>("UserId")
142
+ .HasColumnType("nvarchar(450)");
143
+
144
+ b.Property<string>("LoginProvider")
145
+ .HasColumnType("nvarchar(450)");
146
+
147
+ b.Property<string>("Name")
148
+ .HasColumnType("nvarchar(450)");
149
+
150
+ b.Property<string>("Value")
151
+ .HasColumnType("nvarchar(max)");
152
+
153
+ b.HasKey("UserId", "LoginProvider", "Name");
154
+
155
+ b.ToTable("AspNetUserTokens", (string)null);
156
+ });
157
+
158
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.ApplicationUser", b =>
159
+ {
160
+ b.Property<string>("Id")
161
+ .HasColumnType("nvarchar(450)");
162
+
163
+ b.Property<int>("AccessFailedCount")
164
+ .HasColumnType("int");
165
+
166
+ b.Property<string>("ConcurrencyStamp")
167
+ .IsConcurrencyToken()
168
+ .HasColumnType("nvarchar(max)");
169
+
170
+ b.Property<string>("Email")
171
+ .HasMaxLength(256)
172
+ .HasColumnType("nvarchar(256)");
173
+
174
+ b.Property<bool>("EmailConfirmed")
175
+ .HasColumnType("bit");
176
+
177
+ b.Property<bool>("LockoutEnabled")
178
+ .HasColumnType("bit");
179
+
180
+ b.Property<DateTimeOffset?>("LockoutEnd")
181
+ .HasColumnType("datetimeoffset");
182
+
183
+ b.Property<string>("NormalizedEmail")
184
+ .HasMaxLength(256)
185
+ .HasColumnType("nvarchar(256)");
186
+
187
+ b.Property<string>("NormalizedUserName")
188
+ .HasMaxLength(256)
189
+ .HasColumnType("nvarchar(256)");
190
+
191
+ b.Property<string>("PasswordHash")
192
+ .HasColumnType("nvarchar(max)");
193
+
194
+ b.Property<string>("PhoneNumber")
195
+ .HasColumnType("nvarchar(max)");
196
+
197
+ b.Property<bool>("PhoneNumberConfirmed")
198
+ .HasColumnType("bit");
199
+
200
+ b.Property<string>("SecurityStamp")
201
+ .HasColumnType("nvarchar(max)");
202
+
203
+ b.Property<string>("SubscriptionPlan")
204
+ .IsRequired()
205
+ .HasColumnType("nvarchar(max)");
206
+
207
+ b.Property<string>("TenantId")
208
+ .HasColumnType("nvarchar(max)")
209
+ .HasColumnName("TenantId");
210
+
211
+ b.Property<bool>("TwoFactorEnabled")
212
+ .HasColumnType("bit");
213
+
214
+ b.Property<string>("UserName")
215
+ .HasMaxLength(256)
216
+ .HasColumnType("nvarchar(256)");
217
+
218
+ b.HasKey("Id");
219
+
220
+ b.HasIndex("NormalizedEmail")
221
+ .HasDatabaseName("EmailIndex");
222
+
223
+ b.HasIndex("NormalizedUserName")
224
+ .IsUnique()
225
+ .HasDatabaseName("UserNameIndex")
226
+ .HasFilter("[NormalizedUserName] IS NOT NULL");
227
+
228
+ b.ToTable("AspNetUsers", (string)null);
229
+ });
230
+
231
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
232
+ {
233
+ b.Property<int>("Id")
234
+ .ValueGeneratedOnAdd()
235
+ .HasColumnType("int");
236
+
237
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
238
+
239
+ b.Property<string>("ClientEmail")
240
+ .HasColumnType("nvarchar(max)");
241
+
242
+ b.Property<string>("ClientName")
243
+ .IsRequired()
244
+ .HasMaxLength(150)
245
+ .HasColumnType("nvarchar(150)");
246
+
247
+ b.Property<string>("InvoiceNumber")
248
+ .IsRequired()
249
+ .HasMaxLength(50)
250
+ .HasColumnType("nvarchar(50)");
251
+
252
+ b.Property<DateTime>("IssueDate")
253
+ .HasColumnType("datetime2");
254
+
255
+ b.Property<string>("Status")
256
+ .IsRequired()
257
+ .HasColumnType("nvarchar(max)");
258
+
259
+ b.Property<string>("TenantId")
260
+ .IsRequired()
261
+ .HasColumnType("nvarchar(max)")
262
+ .HasColumnName("TenantId");
263
+
264
+ b.Property<decimal>("TotalAmount")
265
+ .HasColumnType("decimal(18,2)");
266
+
267
+ b.HasKey("Id");
268
+
269
+ b.ToTable("Invoices", (string)null);
270
+ });
271
+
272
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
273
+ {
274
+ b.Property<int>("Id")
275
+ .ValueGeneratedOnAdd()
276
+ .HasColumnType("int");
277
+
278
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
279
+
280
+ b.Property<int>("InvoiceId")
281
+ .HasColumnType("int");
282
+
283
+ b.Property<string>("ProductName")
284
+ .IsRequired()
285
+ .HasMaxLength(250)
286
+ .HasColumnType("nvarchar(250)");
287
+
288
+ b.Property<int>("Quantity")
289
+ .HasColumnType("int");
290
+
291
+ b.Property<decimal>("UnitPrice")
292
+ .HasColumnType("decimal(18,2)");
293
+
294
+ b.HasKey("Id");
295
+
296
+ b.HasIndex("InvoiceId");
297
+
298
+ b.ToTable("InvoiceItem");
299
+ });
300
+
301
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
302
+ {
303
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
304
+ .WithMany()
305
+ .HasForeignKey("RoleId")
306
+ .OnDelete(DeleteBehavior.Cascade)
307
+ .IsRequired();
308
+ });
309
+
310
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
311
+ {
312
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
313
+ .WithMany()
314
+ .HasForeignKey("UserId")
315
+ .OnDelete(DeleteBehavior.Cascade)
316
+ .IsRequired();
317
+ });
318
+
319
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
320
+ {
321
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
322
+ .WithMany()
323
+ .HasForeignKey("UserId")
324
+ .OnDelete(DeleteBehavior.Cascade)
325
+ .IsRequired();
326
+ });
327
+
328
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
329
+ {
330
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
331
+ .WithMany()
332
+ .HasForeignKey("RoleId")
333
+ .OnDelete(DeleteBehavior.Cascade)
334
+ .IsRequired();
335
+
336
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
337
+ .WithMany()
338
+ .HasForeignKey("UserId")
339
+ .OnDelete(DeleteBehavior.Cascade)
340
+ .IsRequired();
341
+ });
342
+
343
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
344
+ {
345
+ b.HasOne("QuickInvoiceSaaS.Models.ApplicationUser", null)
346
+ .WithMany()
347
+ .HasForeignKey("UserId")
348
+ .OnDelete(DeleteBehavior.Cascade)
349
+ .IsRequired();
350
+ });
351
+
352
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.InvoiceItem", b =>
353
+ {
354
+ b.HasOne("QuickInvoiceSaaS.Models.Invoice", "Invoice")
355
+ .WithMany("Items")
356
+ .HasForeignKey("InvoiceId")
357
+ .OnDelete(DeleteBehavior.Cascade)
358
+ .IsRequired();
359
+
360
+ b.Navigation("Invoice");
361
+ });
362
+
363
+ modelBuilder.Entity("QuickInvoiceSaaS.Models.Invoice", b =>
364
+ {
365
+ b.Navigation("Items");
366
+ });
367
+ #pragma warning restore 612, 618
368
+ }
369
+ }
370
+ }
ApplicationUser.cs ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.AspNetCore.Identity;
2
+
3
+ namespace QuickInvoiceSaaS.Models
4
+ {
5
+ public class ApplicationUser : IdentityUser
6
+ {
7
+ // إضافة حقل الشركة ليكون جزءاً أساسياً من هويّة المستخدم
8
+ public string TenantId { get; set; } = string.Empty;
9
+ public string SubscriptionPlan { get; set; } = "Free";
10
+ }
11
+ }
DbContextFactory.cs ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.EntityFrameworkCore;
2
+ using Microsoft.EntityFrameworkCore.Design;
3
+ using QuickInvoiceSaaS.Data;
4
+ using QuickInvoiceSaaS.Services;
5
+
6
+ namespace QuickInvoiceSaaS.Data
7
+ {
8
+ public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
9
+ {
10
+ public ApplicationDbContext CreateDbContext(string[] args)
11
+ {
12
+ var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
13
+
14
+ var connectionString = "Server=DESKTOP-7O20K25;Database=QuickInvoiceSaaS_Db;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True";
15
+
16
+ optionsBuilder.UseSqlServer(connectionString);
17
+
18
+ return new ApplicationDbContext(optionsBuilder.Options);
19
+ }
20
+ }
21
+
22
+ public class DummyTenantService : ITenantService
23
+ {
24
+ public string GetTenantId()
25
+ {
26
+ return string.Empty;
27
+ }
28
+ }
29
+ }
Dockerfile.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2
+ WORKDIR /src
3
+ COPY ["quickInvoiceSaaS/quickInvoiceSaaS.csproj", "quickInvoiceSaaS/"]
4
+ RUN dotnet restore "quickInvoiceSaaS/quickInvoiceSaaS.csproj"
5
+ COPY . .
6
+ WORKDIR "/src/quickInvoiceSaaS"
7
+ RUN dotnet build "quickInvoiceSaaS.csproj" -c Release -o /app/build
8
+
9
+ FROM build AS publish
10
+ RUN dotnet publish "quickInvoiceSaaS.csproj" -c Release -o /app/publish /p:UseAppHost=false
11
+
12
+ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
13
+ WORKDIR /app
14
+ COPY --from=publish /app/publish .
15
+ ENV ASPNETCORE_URLS=http://+:7860
16
+ EXPOSE 7860
17
+ ENTRYPOINT ["dotnet", "quickInvoiceSaaS.dll"]
IMustHaveTenant.cs ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ namespace QuickInvoiceSaaS.Models
2
+ {
3
+ public interface IMustHaveTenant
4
+ {
5
+ public string TenantId { get; set; }
6
+ }
7
+ }
Invoice.cs ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System.ComponentModel.DataAnnotations;
2
+ using System.ComponentModel.DataAnnotations.Schema;
3
+
4
+ namespace QuickInvoiceSaaS.Models
5
+ {
6
+ public class Invoice : IMustHaveTenant
7
+ {
8
+ [Key]
9
+ public int Id { get; set; }
10
+
11
+ // تطبيق الواجهة لفصل البيانات
12
+
13
+ [Column("TenantId")]
14
+
15
+ public string TenantId { get; set; } = string.Empty;
16
+
17
+ [Required]
18
+ [MaxLength(50)]
19
+ public string InvoiceNumber { get; set; } = string.Empty; // مثل INV-2026-001
20
+
21
+ [Required]
22
+ [MaxLength(150)]
23
+ public string ClientName { get; set; } = string.Empty;
24
+
25
+ public string? ClientEmail { get; set; }
26
+
27
+ public DateTime IssueDate { get; set; } = DateTime.UtcNow;
28
+
29
+ [Column(TypeName = "decimal(18,2)")]
30
+ public decimal TotalAmount { get; set; }
31
+
32
+ [Required]
33
+ public string Status { get; set; } = "Unpaid"; // Unpaid, Paid, Draft
34
+
35
+ // علاقة One-to-Many مع تفاصيل الفاتورة
36
+ public List<InvoiceItem> Items { get; set; } = new();
37
+ }
38
+ }
InvoiceItem.cs ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System.ComponentModel.DataAnnotations;
2
+ using System.ComponentModel.DataAnnotations.Schema;
3
+
4
+ namespace QuickInvoiceSaaS.Models
5
+ {
6
+ public class InvoiceItem
7
+ {
8
+ [Key]
9
+ public int Id { get; set; }
10
+
11
+ [Required]
12
+ public int InvoiceId { get; set; }
13
+
14
+ [ForeignKey(nameof(InvoiceId))]
15
+ public Invoice? Invoice { get; set; }
16
+
17
+ [Required]
18
+ [MaxLength(250)]
19
+ public string ProductName { get; set; } = string.Empty;
20
+
21
+ public int Quantity { get; set; } = 1;
22
+
23
+ [Column(TypeName = "decimal(18,2)")]
24
+ public decimal UnitPrice { get; set; }
25
+
26
+ [Column(TypeName = "decimal(18,2)")]
27
+ public decimal LineTotal => Quantity * UnitPrice; // حساب تلقائي
28
+ }
29
+ }
InvoicesController.cs ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.AspNetCore.Mvc;
2
+ using Microsoft.EntityFrameworkCore;
3
+ using QuickInvoiceSaaS.Data;
4
+ using QuickInvoiceSaaS.Models;
5
+
6
+ namespace QuickInvoiceSaaS.Controllers
7
+ {
8
+ [Route("api/[controller]")]
9
+ [ApiController]
10
+ public class InvoicesController : ControllerBase
11
+ {
12
+ private readonly ApplicationDbContext _context;
13
+
14
+ public InvoicesController(ApplicationDbContext context)
15
+ {
16
+ _context = context;
17
+ }
18
+
19
+ // 1. دالة جلب الفواتير (ستجلب تلقائياً فواتير الشركة الحالية فقط بفضل الـ Filter)
20
+ [HttpGet]
21
+ public async Task<IActionResult> GetAll()
22
+ {
23
+ var invoices = await _context.Invoices.Include(i => i.Items).ToListAsync();
24
+ return Ok(invoices);
25
+ }
26
+
27
+ // 2. دالة إنشاء فاتورة جديدة (سيتم حقن الـ TenantId تلقائياً قبل الحفظ)
28
+ [HttpPost]
29
+ public async Task<IActionResult> Create([FromBody] Invoice invoice)
30
+ {
31
+ if (!ModelState.IsValid) return BadRequest(ModelState);
32
+
33
+ _context.Invoices.Add(invoice);
34
+ await _context.SaveChangesAsync();
35
+
36
+ return Ok(new { message = "تم إنشاء الفاتورة بنجاح!", invoiceId = invoice.Id });
37
+ }
38
+ }
39
+ }
InvoicesWebController.cs ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.AspNetCore.Authorization;
2
+ using Microsoft.AspNetCore.Identity;
3
+ using Microsoft.AspNetCore.Mvc;
4
+ using Microsoft.EntityFrameworkCore;
5
+ using QuickInvoiceSaaS.Data;
6
+ using QuickInvoiceSaaS.Models;
7
+
8
+ namespace QuickInvoiceSaaS.Controllers
9
+ {
10
+ [Authorize] // 🔥 حماية الـ Controller بالكامل (لن يدخل أحد إلا بتسجيل دخول)
11
+ public class InvoicesWebController : Controller
12
+ {
13
+ private readonly ApplicationDbContext _context;
14
+ private readonly UserManager<ApplicationUser> _userManager;
15
+
16
+ public InvoicesWebController(ApplicationDbContext context, UserManager<ApplicationUser> userManager)
17
+ {
18
+ _context = context;
19
+ _userManager = userManager;
20
+ }
21
+
22
+ // --- 1. عرض فواتير الشركة الخاصة بالمستخدم فقط ---
23
+ public async Task<IActionResult> Index()
24
+ {
25
+ // جلب بيانات المستخدم الحالي المسجل دخوله
26
+ var user = await _userManager.GetUserAsync(User);
27
+ if (user == null) return Challenge();
28
+
29
+ var tenantId = user.TenantId;
30
+ ViewData["CurrentTenant"] = tenantId;
31
+
32
+ // عزل حقيقي: جلب الفواتير التي تطابق TenantId الخاص بالمستخدم فقط!
33
+ var invoices = await _context.Invoices
34
+ .IgnoreQueryFilters()
35
+ .Where(i => i.TenantId == tenantId)
36
+ .ToListAsync();
37
+
38
+ // حساب الإحصائيات للواجهة بناءً على بيانات الشركة الحالية
39
+ ViewData["TotalInvoicesCount"] = invoices.Count;
40
+ ViewData["UniqueClientsCount"] = invoices.Select(i => i.ClientName).Distinct().Count();
41
+
42
+ return View(invoices);
43
+ }
44
+ // --- 4. صفحة تعديل الفاتورة (HttpGet) ---
45
+ public async Task<IActionResult> Edit(int? id)
46
+ {
47
+ if (id == null) return NotFound();
48
+
49
+ // جلب المستخدم الحالي لمعرفة شركته
50
+ var user = await _userManager.GetUserAsync(User);
51
+ if (user == null) return Challenge();
52
+
53
+ // جلب الفاتورة بشرط أن تكون تابعة لنفس الـ TenantId لحماية البيانات 🔐
54
+ var invoice = await _context.Invoices
55
+ .IgnoreQueryFilters()
56
+ .FirstOrDefaultAsync(i => i.Id == id && i.TenantId == user.TenantId);
57
+
58
+ if (invoice == null) return Forbid(); // منع الوصول إذا كانت الفاتورة لشركة أخرى
59
+
60
+ return View(invoice);
61
+ }
62
+
63
+ // --- 5. حفظ تعديل الفاتورة (HttpPost) ---
64
+ [HttpPost]
65
+ [ValidateAntiForgeryToken]
66
+ public async Task<IActionResult> Edit(int id, Invoice invoice)
67
+ {
68
+ if (id != invoice.Id) return NotFound();
69
+
70
+ var user = await _userManager.GetUserAsync(User);
71
+ if (user == null) return Challenge();
72
+
73
+ // التأكد قبل الحفظ أن الفاتورة الأصلية تابعة للمستخدم الحالي
74
+ var existingInvoice = await _context.Invoices
75
+ .IgnoreQueryFilters()
76
+ .AsNoTracking()
77
+ .FirstOrDefaultAsync(i => i.Id == id && i.TenantId == user.TenantId);
78
+
79
+ if (existingInvoice == null) return Forbid();
80
+
81
+ if (ModelState.IsValid)
82
+ {
83
+ try
84
+ {
85
+ invoice.TenantId = user.TenantId; // إعادة حقن الـ TenantId لضمان عدم التلاعب
86
+ _context.Update(invoice);
87
+ await _context.SaveChangesAsync();
88
+ return RedirectToAction(nameof(Index));
89
+ }
90
+ catch (DbUpdateConcurrencyException)
91
+ {
92
+ if (!_context.Invoices.Any(e => e.Id == invoice.Id)) return NotFound();
93
+ else throw;
94
+ }
95
+ }
96
+ return View(invoice);
97
+ }
98
+
99
+ // --- 6. حذف الفاتورة مباشرة (HttpPost لحماية أمنية أفضل) ---
100
+ [HttpPost]
101
+ [ValidateAntiForgeryToken]
102
+ public async Task<IActionResult> Delete(int id)
103
+ {
104
+ var user = await _userManager.GetUserAsync(User);
105
+ if (user == null) return Challenge();
106
+
107
+ // جلب الفاتورة الخاصة بالشركة فقط لحذفها
108
+ var invoice = await _context.Invoices
109
+ .IgnoreQueryFilters()
110
+ .FirstOrDefaultAsync(i => i.Id == id && i.TenantId == user.TenantId);
111
+
112
+ if (invoice == null) return Forbid();
113
+
114
+ _context.Invoices.Remove(invoice);
115
+ await _context.SaveChangesAsync();
116
+ return RedirectToAction(nameof(Index));
117
+ }
118
+
119
+ // --- 2. صفحة إنشاء فاتورة جديدة (HttpGet) ---
120
+ public IActionResult Create() => View();
121
+
122
+ [HttpPost]
123
+ [ValidateAntiForgeryToken]
124
+ public async Task<IActionResult> Create(Invoice invoice)
125
+ {
126
+ var user = await _userManager.GetUserAsync(User);
127
+ if (user == null) return Challenge();
128
+
129
+ // 🔒 فحص خطة الاشتراك والحد الأقصى للفواتير
130
+ if (user.SubscriptionPlan == "Free")
131
+ {
132
+ // حساب عدد فواتير هذه الشركة حالياً في قاعدة البيانات
133
+ var currentInvoicesCount = await _context.Invoices
134
+ .IgnoreQueryFilters()
135
+ .CountAsync(i => i.TenantId == user.TenantId);
136
+
137
+ if (currentInvoicesCount >= 3)
138
+ {
139
+ // إظهار رسالة خطأ تمنع الحفظ وتطلب الترقية
140
+ ModelState.AddModelError("", "⚠️ لقد استهلكت الحد الأقصى للباقة المجانية (3 فواتير). يرجى الترقية إلى الباقة الممتازة لإضافة المزيد!");
141
+ return View(invoice);
142
+ }
143
+ }
144
+
145
+ invoice.TenantId = user.TenantId;
146
+
147
+ try
148
+ {
149
+ _context.Invoices.Add(invoice);
150
+ await _context.SaveChangesAsync();
151
+ return RedirectToAction(nameof(Index));
152
+ }
153
+ catch (Exception ex)
154
+ {
155
+ ModelState.AddModelError("", "حدث خطأ أثناء الحفظ: " + ex.Message);
156
+ }
157
+
158
+ return View(invoice);
159
+ }
160
+ }
161
+ }
LoginViewModel.cs ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ namespace QuickInvoiceSaaS.Models
2
+ {
3
+ public class LoginViewModel
4
+ {
5
+ public string Email { get; set; } = string.Empty;
6
+ public string Password { get; set; } = string.Empty;
7
+ public bool RememberMe { get; set; }
8
+ }
9
+ }
Program.cs ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 
2
+ using Microsoft.AspNetCore.Identity;
3
+ using Microsoft.EntityFrameworkCore;
4
+ using QuickInvoiceSaaS.Data;
5
+ using QuickInvoiceSaaS.Models;
6
+ using QuickInvoiceSaaS.Services;
7
+
8
+ var builder = WebApplication.CreateBuilder(args);
9
+
10
+ // ==========================================
11
+ // 1. تسجيل الخدمات (Configure Services)
12
+ // ==========================================
13
+
14
+ // تفعيل الوصول إلى بيانات الـ HTTP Request (مثل الـ Headers والـ Claims)
15
+ builder.Services.AddHttpContextAccessor();
16
+
17
+ // تسجيل خدمة جلب الـ Tenant الحالي وتحديد عمرها بـ Scoped (لكل طلب مستقل)
18
+ builder.Services.AddScoped<ITenantService, TenantService>();
19
+
20
+ // تسجيل الـ DbContext وربطه بـ SQL Server ونص الاتصال من الـ appsettings.json
21
+ builder.Services.AddDbContext<ApplicationDbContext>(options =>
22
+ options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
23
+
24
+ // تسجيل خدمات الـ Controllers ودعم الـ Swagger لتجربة الـ APIs
25
+ builder.Services.AddControllers();
26
+ builder.Services.AddControllersWithViews();
27
+ builder.Services.AddEndpointsApiExplorer();
28
+ builder.Services.AddSwaggerGen(options =>
29
+ {
30
+ options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "QuickInvoice SaaS API", Version = "v1" });
31
+
32
+ options.AddSecurityDefinition("TenantId", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
33
+ {
34
+ In = Microsoft.OpenApi.Models.ParameterLocation.Header,
35
+ Name = "X-Tenant-Id", // اسم الهيدر الذي يبحث عنه الكود لديك
36
+ Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey,
37
+ Description = "الرجاء إدخال معرف الشركة هنا (مثل: Company-A)"
38
+ });
39
+
40
+ options.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
41
+ {
42
+ {
43
+ new Microsoft.OpenApi.Models.OpenApiSecurityScheme
44
+ {
45
+ Reference = new Microsoft.OpenApi.Models.OpenApiReference
46
+ {
47
+ Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
48
+ Id = "TenantId"
49
+ }
50
+ },
51
+ new string[] {}
52
+ }
53
+ });
54
+ });
55
+ // إضافة خدمات نظام الهوية المخصص للمستخدمين والشركات
56
+ builder.Services.AddIdentity<ApplicationUser, IdentityRole>(options =>
57
+ {
58
+ // إعدادات اختيارية لكلمة المرور (يمكنك تعديلها حسب رغبتك)
59
+ options.Password.RequireDigit = false;
60
+ options.Password.RequiredLength = 6;
61
+ options.Password.RequireNonAlphanumeric = false;
62
+ options.Password.RequireUppercase = false;
63
+ options.Password.RequireLowercase = false;
64
+ })
65
+ .AddEntityFrameworkStores<ApplicationDbContext>()
66
+ .AddDefaultTokenProviders();
67
+
68
+ // ضبط مسارات الـ Cookie في حال حاول مستخدم غير مسجل الدخول دخول صفحات محمية
69
+ builder.Services.ConfigureApplicationCookie(options =>
70
+ {
71
+ options.LoginPath = "/Account/Login";
72
+ options.AccessDeniedPath = "/Account/AccessDenied";
73
+ });
74
+
75
+ var app = builder.Build();
76
+
77
+ // ==========================================
78
+ // 2. خط أنابيب الطلبات (Configure HTTP Pipeline)
79
+ // ==========================================
80
+
81
+ // تفعيل واجهة Swagger للاختبار في بيئة التطوير (Development)
82
+ if (app.Environment.IsDevelopment())
83
+ {
84
+ app.UseSwagger();
85
+ app.UseSwaggerUI();
86
+ }
87
+
88
+ app.UseHttpsRedirection();
89
+
90
+ app.UseAuthorization();
91
+
92
+ // ربط مسارات الـ Controllers بالـ Routing الأساسي للتطبيق
93
+ app.MapControllers();
94
+ app.MapControllerRoute(
95
+ name: "default",
96
+ pattern: "{controller=InvoicesWeb}/{action=Index}/{id?}");
97
+ app.UseRouting();
98
+
99
+ // 🔥 السطرين الأهم للتأكد من فحص هوية وصلاحيات المستخدمين
100
+ app.UseAuthentication();
101
+ app.UseAuthorization();
102
+
103
+ app.MapControllerRoute(
104
+ name: "default",
105
+ pattern: "{controller=InvoicesWeb}/{action=Index}/{id?}");
106
+
107
+ // تشغيل التطبيق
108
+ app.Run();
RegisterViewModel.cs ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ namespace QuickInvoiceSaaS.Models
2
+ {
3
+ public class RegisterViewModel
4
+ {
5
+ public string Email { get; set; } = string.Empty;
6
+ public string Password { get; set; } = string.Empty;
7
+ public string TenantId { get; set; } = string.Empty; // اسم الشركة المسجل عليها
8
+ public string SubscriptionPlan { get; set; } = "Free";
9
+
10
+ }
11
+ }
Tenant.cs ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System.ComponentModel.DataAnnotations;
2
+
3
+ namespace QuickInvoiceSaaS.Models
4
+ {
5
+ public class Tenant
6
+ {
7
+ [Key]
8
+ public string Id { get; set; } = Guid.NewGuid().ToString(); // معرف فريد لكل شركة مشتركة
9
+
10
+ [Required]
11
+ [MaxLength(150)]
12
+ public string BusinessName { get; set; } = string.Empty;
13
+
14
+ public string? LogoUrl { get; set; }
15
+
16
+ [Required]
17
+ [MaxLength(10)]
18
+ public string Currency { get; set; } = "USD"; // العملة الافتراضية للفواتير
19
+
20
+ public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
21
+ }
22
+ }
appsettings.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "ConnectionStrings": {
3
+ "DefaultConnection": "postgresql://postgres:Ekthetiger@579@db.wgthqndvxujqvvtdkojq.supabase.co:5432/postgres"
4
+ },
5
+ "Logging": {
6
+ "LogLevel": {
7
+ "Default": "Information",
8
+ "Microsoft.AspNetCore": "Warning"
9
+ }
10
+ },
11
+ "AllowedHosts": "*"
12
+ }
quickInvoiceSaaS.csproj ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <ItemGroup>
10
+ <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
11
+ <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
12
+ <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
13
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
14
+ <PrivateAssets>all</PrivateAssets>
15
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16
+ </PackageReference>
17
+ <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0" />
18
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
19
+ </ItemGroup>
20
+
21
+ </Project>