Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
ProjectsStatusManagement
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
ProjectsStatusManagement
Commits
3523f34a
Commit
3523f34a
authored
Aug 10, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Persistence an bakjobs
parent
624fadfb
Changes
15
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
3158 additions
and
55 deletions
+3158
-55
AppDbContext.cs
...Infrastructure.Persistence/AppDataContext/AppDbContext.cs
+5
-0
DependencyInjection.cs
...ment.Infrastructure.Persistence/DI/DependencyInjection.cs
+4
-0
CustomerEntityConfiguration.cs
...ence/EntitiesConfiguration/CustomerEntityConfiguration.cs
+0
-3
FinicialSpendingEntityConfiguration.cs
...itiesConfiguration/FinicialSpendingEntityConfiguration.cs
+2
-9
ProjectEntityConfiguration.cs
...tence/EntitiesConfiguration/ProjectEntityConfiguration.cs
+6
-4
20240810090056_AddDomainsUpdate4.Designer.cs
...e/Migrations/20240810090056_AddDomainsUpdate4.Designer.cs
+923
-0
20240810090056_AddDomainsUpdate4.cs
...ersistence/Migrations/20240810090056_AddDomainsUpdate4.cs
+135
-0
20240810091617_AddDomainsUpdate5.Designer.cs
...e/Migrations/20240810091617_AddDomainsUpdate5.Designer.cs
+926
-0
20240810091617_AddDomainsUpdate5.cs
...ersistence/Migrations/20240810091617_AddDomainsUpdate5.cs
+25
-0
20240810104919_AddDomainsUpdate6.Designer.cs
...e/Migrations/20240810104919_AddDomainsUpdate6.Designer.cs
+934
-0
20240810104919_AddDomainsUpdate6.cs
...ersistence/Migrations/20240810104919_AddDomainsUpdate6.cs
+34
-0
AppDbContextModelSnapshot.cs
...cture.Persistence/Migrations/AppDbContextModelSnapshot.cs
+44
-39
SeedData.cs
...nt.Infrastructure.Persistence/SeedDataContext/SeedData.cs
+32
-0
UnitOfWork.cs
PSManagement.Infrastructure.Persistence/UoW/UnitOfWork.cs
+84
-0
PSManagement.Infrastructure.csproj
...agement.Infrastructure/PSManagement.Infrastructure.csproj
+4
-0
No files found.
PSManagement.Infrastructure.Persistence/AppDataContext/AppDbContext.cs
View file @
3523f34a
...
...
@@ -5,6 +5,8 @@ using PSManagement.Domain.Identity.Entities;
using
PSManagement.Domain.Projects.Entities
;
using
PSManagement.Domain.Tracking
;
using
PSManagement.Domain.Tracking.Entities
;
using
PSManagement.Infrastructure.Persistence.SeedDataContext
;
using
PSManagement.SharedKernel.Entities
;
namespace
PSManagement.Infrastructure.Persistence
{
...
...
@@ -37,6 +39,9 @@ namespace PSManagement.Infrastructure.Persistence
{
modelBuilder
.
ApplyConfigurationsFromAssembly
(
typeof
(
AppDbContext
).
Assembly
);
// modelBuilder.Entity<BaseEntity>().Ignore(e => e.Events);
SeedData
.
SeedAsync
(
modelBuilder
).
Wait
();
base
.
OnModelCreating
(
modelBuilder
);
...
...
PSManagement.Infrastructure.Persistence/DI/DependencyInjection.cs
View file @
3523f34a
...
...
@@ -7,6 +7,8 @@ using PSManagement.Domain.Projects.Repositories;
using
PSManagement.Infrastructure.Persistence.Repositories.CustomerRepository
;
using
PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository
;
using
PSManagement.Infrastructure.Persistence.Repositories.UserRepository
;
using
PSManagement.Infrastructure.Persistence.UoW
;
using
PSManagement.SharedKernel.Interfaces
;
namespace
PSManagement.Infrastructure.Persistence.DI
{
...
...
@@ -23,6 +25,8 @@ namespace PSManagement.Infrastructure.Persistence.DI
services
.
AddScoped
<
IProjectsRepository
,
ProjectsRepository
>();
services
.
AddScoped
<
IUnitOfWork
,
UnitOfWork
>();
return
services
;
}
...
...
PSManagement.Infrastructure.Persistence/EntitiesConfiguration/CustomerEntityConfiguration.cs
View file @
3523f34a
...
...
@@ -23,9 +23,6 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
}
);
builder
.
HasMany
(
e
=>
e
.
Projects
).
WithOne
(
e
=>
e
.
Proposer
);
builder
.
OwnsMany
(
c
=>
c
.
ContactInfo
);
}
...
...
PSManagement.Infrastructure.Persistence/EntitiesConfiguration/FinicialSpendingEntityConfiguration.cs
View file @
3523f34a
...
...
@@ -5,10 +5,10 @@ using PSManagement.Domain.Projects.Entities;
namespace
PSManagement.Infrastructure.Persistence.EntitiesConfiguration
{
public
class
FinicialSpendingEntityConfiguration
:
IEntityTypeConfiguration
<
Fin
i
ncialSpending
>
IEntityTypeConfiguration
<
Fin
a
ncialSpending
>
{
public
void
Configure
(
EntityTypeBuilder
<
Fin
i
ncialSpending
>
builder
)
public
void
Configure
(
EntityTypeBuilder
<
Fin
a
ncialSpending
>
builder
)
{
builder
.
OwnsOne
(
e
=>
e
.
ExternalPurchase
,
p
=>
{
...
...
@@ -17,13 +17,6 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
});
builder
.
OwnsOne
(
e
=>
e
.
LocalPurchase
,
p
=>
{
p
.
Property
(
e
=>
e
.
Ammount
).
HasColumnName
(
"LocalPurchaseAmmount"
);
p
.
Property
(
e
=>
e
.
Currency
).
HasColumnName
(
"LocalPurchaseCurrency"
).
HasDefaultValue
(
"SP"
);
});
}
}
}
PSManagement.Infrastructure.Persistence/EntitiesConfiguration/ProjectEntityConfiguration.cs
View file @
3523f34a
...
...
@@ -31,6 +31,8 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
p
.
Property
(
e
=>
e
.
Description
).
HasColumnName
(
"Description"
);
p
.
Property
(
e
=>
e
.
Code
).
HasColumnName
(
"Code"
);
p
.
Property
(
e
=>
e
.
Name
).
HasColumnName
(
"Name"
);
p
.
Property
(
e
=>
e
.
StartDate
).
HasColumnName
(
"StartDate"
);
p
.
Property
(
e
=>
e
.
ExpectedEndDate
).
HasColumnName
(
"ExpectedEndDate"
);
}
...
...
@@ -54,15 +56,15 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
p
.
Property
(
e
=>
e
.
ProposingBookNumber
).
HasColumnName
(
"ProposingBookNumber"
);
}
);
builder
.
OwnsOne
(
c
=>
c
.
Fin
i
ncialFund
,
builder
.
OwnsOne
(
c
=>
c
.
Fin
a
ncialFund
,
p
=>
{
p
.
Property
(
e
=>
e
.
Fin
i
cialStatus
).
HasColumnName
(
"FinicialStatus"
);
p
.
Property
(
e
=>
e
.
Fin
an
cialStatus
).
HasColumnName
(
"FinicialStatus"
);
p
.
Property
(
e
=>
e
.
Source
).
HasColumnName
(
"FinicialSource"
);
}
);
builder
.
HasOne
(
e
=>
e
.
ProjectStatus
).
WithMany
();
builder
.
HasMany
(
e
=>
e
.
Fin
i
ncialSpending
);
builder
.
HasMany
(
e
=>
e
.
Fin
a
ncialSpending
);
builder
.
HasMany
(
e
=>
e
.
Tracks
).
WithOne
(
e
=>
e
.
Project
).
HasForeignKey
(
e
=>
e
.
ProjectId
);
}
...
...
PSManagement.Infrastructure.Persistence/Migrations/20240810090056_AddDomainsUpdate4.Designer.cs
0 → 100644
View file @
3523f34a
This diff is collapsed.
Click to expand it.
PSManagement.Infrastructure.Persistence/Migrations/20240810090056_AddDomainsUpdate4.cs
0 → 100644
View file @
3523f34a
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
PSManagement.Infrastructure.Persistence.Migrations
{
public
partial
class
AddDomainsUpdate4
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FinincialSpending_Projects_ProjectId"
,
table
:
"FinincialSpending"
);
migrationBuilder
.
DropPrimaryKey
(
name
:
"PK_FinincialSpending"
,
table
:
"FinincialSpending"
);
migrationBuilder
.
DropColumn
(
name
:
"LocalPurchaseAmmount"
,
table
:
"FinincialSpending"
);
migrationBuilder
.
DropColumn
(
name
:
"LocalPurchaseCurrency"
,
table
:
"FinincialSpending"
);
migrationBuilder
.
RenameTable
(
name
:
"FinincialSpending"
,
newName
:
"FinancialSpending"
);
migrationBuilder
.
RenameIndex
(
name
:
"IX_FinincialSpending_ProjectId"
,
table
:
"FinancialSpending"
,
newName
:
"IX_FinancialSpending_ProjectId"
);
migrationBuilder
.
AddColumn
<
int
>(
name
:
"LocalPurchase"
,
table
:
"FinancialSpending"
,
type
:
"int"
,
nullable
:
false
,
defaultValue
:
0
);
migrationBuilder
.
AddPrimaryKey
(
name
:
"PK_FinancialSpending"
,
table
:
"FinancialSpending"
,
column
:
"Id"
);
migrationBuilder
.
InsertData
(
table
:
"Departments"
,
columns
:
new
[]
{
"Id"
,
"Name"
},
values
:
new
object
[]
{
1
,
"قسم المعلوميات"
});
migrationBuilder
.
InsertData
(
table
:
"Departments"
,
columns
:
new
[]
{
"Id"
,
"Name"
},
values
:
new
object
[]
{
2
,
"قسم النظم الإلكترونيى"
});
migrationBuilder
.
InsertData
(
table
:
"Departments"
,
columns
:
new
[]
{
"Id"
,
"Name"
},
values
:
new
object
[]
{
3
,
"شؤون الطلاب"
});
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FinancialSpending_Projects_ProjectId"
,
table
:
"FinancialSpending"
,
column
:
"ProjectId"
,
principalTable
:
"Projects"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Restrict
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropForeignKey
(
name
:
"FK_FinancialSpending_Projects_ProjectId"
,
table
:
"FinancialSpending"
);
migrationBuilder
.
DropPrimaryKey
(
name
:
"PK_FinancialSpending"
,
table
:
"FinancialSpending"
);
migrationBuilder
.
DeleteData
(
table
:
"Departments"
,
keyColumn
:
"Id"
,
keyValue
:
1
);
migrationBuilder
.
DeleteData
(
table
:
"Departments"
,
keyColumn
:
"Id"
,
keyValue
:
2
);
migrationBuilder
.
DeleteData
(
table
:
"Departments"
,
keyColumn
:
"Id"
,
keyValue
:
3
);
migrationBuilder
.
DropColumn
(
name
:
"LocalPurchase"
,
table
:
"FinancialSpending"
);
migrationBuilder
.
RenameTable
(
name
:
"FinancialSpending"
,
newName
:
"FinincialSpending"
);
migrationBuilder
.
RenameIndex
(
name
:
"IX_FinancialSpending_ProjectId"
,
table
:
"FinincialSpending"
,
newName
:
"IX_FinincialSpending_ProjectId"
);
migrationBuilder
.
AddColumn
<
int
>(
name
:
"LocalPurchaseAmmount"
,
table
:
"FinincialSpending"
,
type
:
"int"
,
nullable
:
true
);
migrationBuilder
.
AddColumn
<
string
>(
name
:
"LocalPurchaseCurrency"
,
table
:
"FinincialSpending"
,
type
:
"nvarchar(max)"
,
nullable
:
true
,
defaultValue
:
"SP"
);
migrationBuilder
.
AddPrimaryKey
(
name
:
"PK_FinincialSpending"
,
table
:
"FinincialSpending"
,
column
:
"Id"
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_FinincialSpending_Projects_ProjectId"
,
table
:
"FinincialSpending"
,
column
:
"ProjectId"
,
principalTable
:
"Projects"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Restrict
);
}
}
}
PSManagement.Infrastructure.Persistence/Migrations/20240810091617_AddDomainsUpdate5.Designer.cs
0 → 100644
View file @
3523f34a
This diff is collapsed.
Click to expand it.
PSManagement.Infrastructure.Persistence/Migrations/20240810091617_AddDomainsUpdate5.cs
0 → 100644
View file @
3523f34a
using
System
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
PSManagement.Infrastructure.Persistence.Migrations
{
public
partial
class
AddDomainsUpdate5
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
AddColumn
<
DateTime
>(
name
:
"ExpectedSpendingDate"
,
table
:
"FinancialSpending"
,
type
:
"datetime2"
,
nullable
:
false
,
defaultValue
:
new
DateTime
(
1
,
1
,
1
,
0
,
0
,
0
,
0
,
DateTimeKind
.
Unspecified
));
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropColumn
(
name
:
"ExpectedSpendingDate"
,
table
:
"FinancialSpending"
);
}
}
}
PSManagement.Infrastructure.Persistence/Migrations/20240810104919_AddDomainsUpdate6.Designer.cs
0 → 100644
View file @
3523f34a
This diff is collapsed.
Click to expand it.
PSManagement.Infrastructure.Persistence/Migrations/20240810104919_AddDomainsUpdate6.cs
0 → 100644
View file @
3523f34a
using
System
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
PSManagement.Infrastructure.Persistence.Migrations
{
public
partial
class
AddDomainsUpdate6
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
AddColumn
<
DateTime
>(
name
:
"ExpectedEndDate"
,
table
:
"Projects"
,
type
:
"datetime2"
,
nullable
:
true
);
migrationBuilder
.
AddColumn
<
DateTime
>(
name
:
"StartDate"
,
table
:
"Projects"
,
type
:
"datetime2"
,
nullable
:
true
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropColumn
(
name
:
"ExpectedEndDate"
,
table
:
"Projects"
);
migrationBuilder
.
DropColumn
(
name
:
"StartDate"
,
table
:
"Projects"
);
}
}
}
PSManagement.Infrastructure.Persistence/Migrations/AppDbContextModelSnapshot.cs
View file @
3523f34a
...
...
@@ -51,6 +51,23 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Departments"
);
b
.
HasData
(
new
{
Id
=
1
,
Name
=
"قسم المعلوميات"
},
new
{
Id
=
2
,
Name
=
"قسم النظم الإلكترونيى"
},
new
{
Id
=
3
,
Name
=
"شؤون الطلاب"
});
});
modelBuilder
.
Entity
(
"PSManagement.Domain.Employees.Entities.Employee"
,
b
=>
...
...
@@ -179,7 +196,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
ToTable
(
"EmployeeParticipate"
);
});
modelBuilder
.
Entity
(
"PSManagement.Domain.Projects.Entities.Fin
i
ncialSpending"
,
b
=>
modelBuilder
.
Entity
(
"PSManagement.Domain.Projects.Entities.Fin
a
ncialSpending"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
...
...
@@ -192,6 +209,12 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
Property
<
string
>(
"Description"
)
.
HasColumnType
(
"nvarchar(max)"
);
b
.
Property
<
DateTime
>(
"ExpectedSpendingDate"
)
.
HasColumnType
(
"datetime2"
);
b
.
Property
<
int
>(
"LocalPurchase"
)
.
HasColumnType
(
"int"
);
b
.
Property
<
int
?>(
"ProjectId"
)
.
HasColumnType
(
"int"
);
...
...
@@ -199,7 +222,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
HasIndex
(
"ProjectId"
);
b
.
ToTable
(
"Fin
i
ncialSpending"
);
b
.
ToTable
(
"Fin
a
ncialSpending"
);
});
modelBuilder
.
Entity
(
"PSManagement.Domain.Projects.Entities.Project"
,
b
=>
...
...
@@ -583,15 +606,15 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
Navigation
(
"Project"
);
});
modelBuilder
.
Entity
(
"PSManagement.Domain.Projects.Entities.Fin
i
ncialSpending"
,
b
=>
modelBuilder
.
Entity
(
"PSManagement.Domain.Projects.Entities.Fin
a
ncialSpending"
,
b
=>
{
b
.
HasOne
(
"PSManagement.Domain.Projects.Entities.Project"
,
null
)
.
WithMany
(
"Fin
i
ncialSpending"
)
.
WithMany
(
"Fin
a
ncialSpending"
)
.
HasForeignKey
(
"ProjectId"
);
b
.
OwnsOne
(
"PSManagement.SharedKernel.ValueObjects.Money"
,
"ExternalPurchase"
,
b1
=>
{
b1
.
Property
<
int
>(
"Fin
i
ncialSpendingId"
)
b1
.
Property
<
int
>(
"Fin
a
ncialSpendingId"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"int"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
...
...
@@ -601,46 +624,20 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.
HasColumnName
(
"ExternalPurchaseAmmount"
);
b1
.
Property
<
string
>(
"Currency"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"nvarchar(max)"
)
.
HasDefaultValue
(
"USD"
)
.
HasColumnName
(
"ExternalPurchaseCurrency"
);
b1
.
HasKey
(
"FinincialSpendingId"
);
b1
.
ToTable
(
"FinincialSpending"
);
b1
.
WithOwner
()
.
HasForeignKey
(
"FinincialSpendingId"
);
});
b
.
OwnsOne
(
"PSManagement.SharedKernel.ValueObjects.Money"
,
"LocalPurchase"
,
b1
=>
{
b1
.
Property
<
int
>(
"FinincialSpendingId"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"int"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b1
.
Property
<
int
>(
"Ammount"
)
.
HasColumnType
(
"int"
)
.
HasColumnName
(
"LocalPurchaseAmmount"
);
b1
.
Property
<
string
>(
"Currency"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"nvarchar(max)"
)
.
HasDefaultValue
(
"SP"
)
.
HasColumnName
(
"LocalPurchaseCurrency"
);
b1
.
HasKey
(
"FinincialSpendingId"
);
b1
.
HasKey
(
"FinancialSpendingId"
);
b1
.
ToTable
(
"Fin
i
ncialSpending"
);
b1
.
ToTable
(
"Fin
a
ncialSpending"
);
b1
.
WithOwner
()
.
HasForeignKey
(
"Fin
i
ncialSpendingId"
);
.
HasForeignKey
(
"Fin
a
ncialSpendingId"
);
});
b
.
Navigation
(
"ExternalPurchase"
);
b
.
Navigation
(
"LocalPurchase"
);
});
modelBuilder
.
Entity
(
"PSManagement.Domain.Projects.Entities.Project"
,
b
=>
...
...
@@ -698,14 +695,14 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.
HasForeignKey
(
"ProjectId"
);
});
b
.
OwnsOne
(
"PSManagement.Domain.Projects.ValueObjects.Fin
incialFund"
,
"Fini
ncialFund"
,
b1
=>
b
.
OwnsOne
(
"PSManagement.Domain.Projects.ValueObjects.Fin
ancialFund"
,
"Fina
ncialFund"
,
b1
=>
{
b1
.
Property
<
int
>(
"ProjectId"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"int"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b1
.
Property
<
string
>(
"Fin
i
cialStatus"
)
b1
.
Property
<
string
>(
"Fin
an
cialStatus"
)
.
HasColumnType
(
"nvarchar(max)"
)
.
HasColumnName
(
"FinicialStatus"
);
...
...
@@ -736,10 +733,18 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.
HasColumnType
(
"nvarchar(max)"
)
.
HasColumnName
(
"Description"
);
b1
.
Property
<
DateTime
>(
"ExpectedEndDate"
)
.
HasColumnType
(
"datetime2"
)
.
HasColumnName
(
"ExpectedEndDate"
);
b1
.
Property
<
string
>(
"Name"
)
.
HasColumnType
(
"nvarchar(max)"
)
.
HasColumnName
(
"Name"
);
b1
.
Property
<
DateTime
>(
"StartDate"
)
.
HasColumnType
(
"datetime2"
)
.
HasColumnName
(
"StartDate"
);
b1
.
HasKey
(
"ProjectId"
);
b1
.
ToTable
(
"Projects"
);
...
...
@@ -773,7 +778,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
Navigation
(
"Executer"
);
b
.
Navigation
(
"Fin
i
ncialFund"
);
b
.
Navigation
(
"Fin
a
ncialFund"
);
b
.
Navigation
(
"ProjectAggreement"
);
...
...
@@ -903,7 +908,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b
.
Navigation
(
"EmployeeParticipates"
);
b
.
Navigation
(
"Fin
i
ncialSpending"
);
b
.
Navigation
(
"Fin
a
ncialSpending"
);
b
.
Navigation
(
"Steps"
);
...
...
PSManagement.Infrastructure.Persistence/SeedDataContext/SeedData.cs
0 → 100644
View file @
3523f34a
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.Logging
;
using
PSManagement.Domain.Employees.Entities
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
PSManagement.Infrastructure.Persistence.SeedDataContext
{
public
class
SeedData
{
public
static
Task
SeedAsync
(
ModelBuilder
builder
)
{
SeedDepartments
(
builder
);
return
Task
.
CompletedTask
;
}
public
static
void
SeedDepartments
(
ModelBuilder
builder
)
{
builder
.
Entity
<
Department
>().
HasData
(
new
Department
{
Id
=
1
,
Name
=
"قسم المعلوميات"
},
new
Department
{
Id
=
2
,
Name
=
"قسم النظم الإلكترونيى"
},
new
Department
{
Id
=
3
,
Name
=
"شؤون الطلاب"
}
)
;
}
}
}
PSManagement.Infrastructure.Persistence/UoW/UnitOfWork.cs
0 → 100644
View file @
3523f34a
using
MediatR
;
using
PSManagement.SharedKernel.Entities
;
using
PSManagement.SharedKernel.Events
;
using
PSManagement.SharedKernel.Interfaces
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
PSManagement.Infrastructure.Persistence.UoW
{
public
class
UnitOfWork
:
IUnitOfWork
{
private
readonly
AppDbContext
_dbContext
;
private
readonly
IMediator
_mediator
;
public
UnitOfWork
(
AppDbContext
dbContext
,
IMediator
mediator
)
{
_dbContext
=
dbContext
;
_mediator
=
mediator
;
}
public
async
Task
SaveChangesAsync
(
CancellationToken
cancellationToken
=
default
)
{
await
DispatchEventsAsync
();
await
_dbContext
.
SaveChangesAsync
(
cancellationToken
);
}
private
async
Task
DispatchEventsAsync
()
{
var
processedDomainEvents
=
new
List
<
IDomainEvent
>();
var
unprocessedDomainEvents
=
GetDomainEvents
().
AsEnumerable
();
// this is needed incase another DomainEvent is published from a DomainEventHandler
while
(
unprocessedDomainEvents
.
Any
())
{
await
DispatchDomainEventsAsync
(
unprocessedDomainEvents
);
processedDomainEvents
.
AddRange
(
unprocessedDomainEvents
);
unprocessedDomainEvents
=
GetDomainEvents
()
.
Where
(
e
=>
!
processedDomainEvents
.
Contains
(
e
))
.
ToList
();
}
ClearDomainEvents
();
}
private
List
<
IDomainEvent
>
GetDomainEvents
()
{
var
aggregateRoots
=
GetTrackedEntites
();
return
aggregateRoots
.
SelectMany
(
x
=>
x
.
Events
)
.
ToList
();
}
private
List
<
BaseEntity
>
GetTrackedEntites
()
{
return
_dbContext
.
ChangeTracker
.
Entries
<
BaseEntity
>()
.
Where
(
x
=>
x
.
Entity
.
Events
!=
null
&&
x
.
Entity
.
Events
.
Any
())
.
Select
(
e
=>
e
.
Entity
)
.
ToList
();
}
private
async
Task
DispatchDomainEventsAsync
(
IEnumerable
<
IDomainEvent
>
domainEvents
)
{
foreach
(
var
domainEvent
in
domainEvents
)
{
await
_mediator
.
Publish
(
domainEvent
);
}
}
private
void
ClearDomainEvents
()
{
var
aggregateRoots
=
GetTrackedEntites
();
aggregateRoots
.
ForEach
(
aggregate
=>
aggregate
.
ClearDomainEvents
());
}
public
void
Dispose
()
{
_dbContext
.
Dispose
();
}
}
}
PSManagement.Infrastructure/PSManagement.Infrastructure.csproj
View file @
3523f34a
...
...
@@ -26,4 +26,8 @@
<ProjectReference Include="..\PSManagement.Domain\PSManagement.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="BackgroundServcies\" />
</ItemGroup>
</Project>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment