Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
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
almohanad.hafez
HIAST-Clinics
Commits
a7ea84d5
Commit
a7ea84d5
authored
Aug 18, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add db seed
parent
ec58ab00
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
204 additions
and
4 deletions
+204
-4
Program.cs
Clinics.Backend/API/Program.cs
+5
-0
SeedHelper.cs
Clinics.Backend/API/SeedDatabaseHelper/SeedHelper.cs
+28
-0
MedicineForms.cs
...es/Medicals/Medicines/MedicineFormValues/MedicineForms.cs
+1
-0
Doctor.cs
Clinics.Backend/Domain/Entities/People/Doctors/Doctor.cs
+1
-0
DoctorStatuses.cs
...eople/Doctors/Shared/DoctorStatusValues/DoctorStatuses.cs
+7
-4
FamilyRoles.cs
...ons/EmployeeFamilyMembers/FamilyRoleValues/FamilyRoles.cs
+1
-0
Genders.cs
...end/Domain/Entities/People/Shared/GenderValues/Genders.cs
+2
-0
SeedDoctorStatuses.cs
...istence/SeedDatabase/DoctorStatuses/SeedDoctorStatuses.cs
+38
-0
SeedFamilyRoles.cs
...d/Persistence/SeedDatabase/FamilyRoles/SeedFamilyRoles.cs
+41
-0
SeedGenders.cs
...s.Backend/Persistence/SeedDatabase/Genders/SeedGenders.cs
+38
-0
ISeed.cs
Clinics.Backend/Persistence/SeedDatabase/ISeed.cs
+8
-0
SeedMedicineForms.cs
...rsistence/SeedDatabase/MedicineForms/SeedMedicineForms.cs
+34
-0
No files found.
Clinics.Backend/API/Program.cs
View file @
a7ea84d5
using
API.Options.Database
;
using
API.SeedDatabaseHelper
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.Options
;
using
Persistence.Context
;
...
...
@@ -61,6 +62,10 @@ builder.Services.AddSwaggerGen();
var
app
=
builder
.
Build
();
#region Seed database
await
SeedHelper
.
Seed
(
app
);
#endregion
// Configure the HTTP request pipeline.
if
(
app
.
Environment
.
IsDevelopment
())
{
...
...
Clinics.Backend/API/SeedDatabaseHelper/SeedHelper.cs
0 → 100644
View file @
a7ea84d5
using
Domain.Entities.Medicals.Medicines.MedicineFormValues
;
using
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Domain.Entities.People.Shared.GenderValues
;
using
Persistence.SeedDatabase
;
namespace
API.SeedDatabaseHelper
;
public
class
SeedHelper
{
public
static
async
Task
Seed
(
IApplicationBuilder
applicationBuilder
)
{
using
(
var
serviceScope
=
applicationBuilder
.
ApplicationServices
.
CreateScope
())
{
var
seedGenders
=
serviceScope
.
ServiceProvider
.
GetRequiredService
<
ISeed
<
Gender
>>();
await
seedGenders
.
Seed
();
var
seedDoctorStatuses
=
serviceScope
.
ServiceProvider
.
GetRequiredService
<
ISeed
<
DoctorStatus
>>();
await
seedDoctorStatuses
.
Seed
();
var
seedFamilyRoles
=
serviceScope
.
ServiceProvider
.
GetRequiredService
<
ISeed
<
FamilyRole
>>();
await
seedFamilyRoles
.
Seed
();
var
seedMedicineForms
=
serviceScope
.
ServiceProvider
.
GetRequiredService
<
ISeed
<
MedicineForm
>>();
await
seedMedicineForms
.
Seed
();
}
}
}
Clinics.Backend/Domain/Entities/Medicals/Medicines/MedicineFormValues/MedicineForms.cs
View file @
a7ea84d5
...
...
@@ -6,6 +6,7 @@ public static class MedicineForms
{
#
region
Constant
values
public
static
int
Count
=>
2
;
public
static
MedicineForm
Tablet
{
get
...
...
Clinics.Backend/Domain/Entities/People/Doctors/Doctor.cs
View file @
a7ea84d5
using
Domain.Entities.People.Doctors.Shared
;
using
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
using
Domain.Entities.People.Doctors.Shared.DoctorStatusValues
;
using
Domain.Entities.People.Shared
;
using
Domain.Primitives
;
using
Domain.Shared
;
...
...
Clinics.Backend/Domain/Entities/People/Doctors/Shared/DoctorStatusValues/DoctorStatuses.cs
View file @
a7ea84d5
using
Domain.Exceptions.InvalidValue
;
using
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
using
Domain.Exceptions.InvalidValue
;
namespace
Domain.Entities.People.Doctors.Shared.
Constants.
DoctorStatusValues
;
namespace
Domain.Entities.People.Doctors.Shared.DoctorStatusValues
;
public
static
class
DoctorStatuses
{
#
region
Constant
values
public
static
int
Count
=>
3
;
public
static
DoctorStatus
Available
{
get
...
...
@@ -21,7 +24,7 @@ public static class DoctorStatuses
{
get
{
var
result
=
DoctorStatus
.
Create
(
"لديه مريض"
,
1
);
var
result
=
DoctorStatus
.
Create
(
"لديه مريض"
,
2
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
result
.
Value
;
...
...
@@ -32,7 +35,7 @@ public static class DoctorStatuses
{
get
{
var
result
=
DoctorStatus
.
Create
(
"مشغول"
,
1
);
var
result
=
DoctorStatus
.
Create
(
"مشغول"
,
3
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
result
.
Value
;
...
...
Clinics.Backend/Domain/Entities/People/Employees/Relations/EmployeeFamilyMembers/FamilyRoleValues/FamilyRoles.cs
View file @
a7ea84d5
...
...
@@ -6,6 +6,7 @@ public static class FamilyRoles
{
#
region
Constant
id
values
public
static
int
Count
=>
4
;
public
static
FamilyRole
Husband
{
get
...
...
Clinics.Backend/Domain/Entities/People/Shared/GenderValues/Genders.cs
View file @
a7ea84d5
...
...
@@ -6,6 +6,8 @@ public static class Genders
{
#
region
Constant
values
public
static
int
Count
=>
2
;
public
static
Gender
Male
{
get
...
...
Clinics.Backend/Persistence/SeedDatabase/DoctorStatuses/SeedDoctorStatuses.cs
0 → 100644
View file @
a7ea84d5
using
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
namespace
Persistence.SeedDatabase.DoctorStatuses
;
public
class
SeedDoctorStatuses
:
ISeed
<
DoctorStatus
>
{
#
region
Ctor
DI
private
readonly
ClinicsDbContext
_clinicsContext
;
public
SeedDoctorStatuses
(
ClinicsDbContext
clinicsContext
)
{
_clinicsContext
=
clinicsContext
;
}
#
endregion
public
async
Task
Seed
()
{
DbSet
<
DoctorStatus
>
doctorStatuses
=
_clinicsContext
.
Set
<
DoctorStatus
>();
if
(
doctorStatuses
.
ToList
().
Count
!=
Domain
.
Entities
.
People
.
Doctors
.
Shared
.
DoctorStatusValues
.
DoctorStatuses
.
Count
)
{
doctorStatuses
.
RemoveRange
(
doctorStatuses
.
ToList
());
doctorStatuses
.
Add
(
Domain
.
Entities
.
People
.
Doctors
.
Shared
.
DoctorStatusValues
.
DoctorStatuses
.
Available
);
doctorStatuses
.
Add
(
Domain
.
Entities
.
People
.
Doctors
.
Shared
.
DoctorStatusValues
.
DoctorStatuses
.
Busy
);
doctorStatuses
.
Add
(
Domain
.
Entities
.
People
.
Doctors
.
Shared
.
DoctorStatusValues
.
DoctorStatuses
.
Working
);
await
_clinicsContext
.
SaveChangesAsync
();
}
}
}
Clinics.Backend/Persistence/SeedDatabase/FamilyRoles/SeedFamilyRoles.cs
0 → 100644
View file @
a7ea84d5
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
namespace
Persistence.SeedDatabase.FamilyRoles
;
public
class
SeedFamilyRoles
:
ISeed
<
FamilyRole
>
{
#
region
Ctor
DI
private
readonly
ClinicsDbContext
_clinicsContext
;
public
SeedFamilyRoles
(
ClinicsDbContext
clinicsContext
)
{
_clinicsContext
=
clinicsContext
;
}
#
endregion
public
async
Task
Seed
()
{
DbSet
<
FamilyRole
>
familyRoles
=
_clinicsContext
.
Set
<
FamilyRole
>();
if
(
familyRoles
.
ToList
().
Count
!=
Domain
.
Entities
.
People
.
Employees
.
Relations
.
EmployeeFamilyMembers
.
FamilyRoleValues
.
FamilyRoles
.
Count
)
{
familyRoles
.
RemoveRange
(
familyRoles
.
ToList
());
familyRoles
.
Add
(
Domain
.
Entities
.
People
.
Employees
.
Relations
.
EmployeeFamilyMembers
.
FamilyRoleValues
.
FamilyRoles
.
Husband
);
familyRoles
.
Add
(
Domain
.
Entities
.
People
.
Employees
.
Relations
.
EmployeeFamilyMembers
.
FamilyRoleValues
.
FamilyRoles
.
Wife
);
familyRoles
.
Add
(
Domain
.
Entities
.
People
.
Employees
.
Relations
.
EmployeeFamilyMembers
.
FamilyRoleValues
.
FamilyRoles
.
Son
);
familyRoles
.
Add
(
Domain
.
Entities
.
People
.
Employees
.
Relations
.
EmployeeFamilyMembers
.
FamilyRoleValues
.
FamilyRoles
.
Daughter
);
await
_clinicsContext
.
SaveChangesAsync
();
}
}
}
Clinics.Backend/Persistence/SeedDatabase/Genders/SeedGenders.cs
0 → 100644
View file @
a7ea84d5
using
Domain.Entities.People.Shared.GenderValues
;
using
Domain.UnitOfWork
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.SeedDatabase
;
namespace
Persistence.Seed.Genders
;
public
class
SeedGenders
:
ISeed
<
Gender
>
{
#
region
Ctor
DI
private
readonly
ClinicsDbContext
_clinicsContext
;
public
SeedGenders
(
ClinicsDbContext
clinicsContext
)
{
_clinicsContext
=
clinicsContext
;
}
#
endregion
public
async
Task
Seed
()
{
DbSet
<
Gender
>
Genders
=
_clinicsContext
.
Set
<
Gender
>();
if
(
Genders
.
ToList
().
Count
!=
Domain
.
Entities
.
People
.
Shared
.
GenderValues
.
Genders
.
Count
)
{
Genders
.
RemoveRange
(
Genders
.
ToList
());
Genders
.
Add
(
Domain
.
Entities
.
People
.
Shared
.
GenderValues
.
Genders
.
Male
);
Genders
.
Add
(
Domain
.
Entities
.
People
.
Shared
.
GenderValues
.
Genders
.
Female
);
await
_clinicsContext
.
SaveChangesAsync
();
}
}
}
Clinics.Backend/Persistence/SeedDatabase/ISeed.cs
0 → 100644
View file @
a7ea84d5
using
Domain.Primitives
;
namespace
Persistence.SeedDatabase
;
public
interface
ISeed
<
TEntity
>
where
TEntity
:
Entity
{
public
Task
Seed
();
}
Clinics.Backend/Persistence/SeedDatabase/MedicineForms/SeedMedicineForms.cs
0 → 100644
View file @
a7ea84d5
using
Domain.Entities.Medicals.Medicines.MedicineFormValues
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
namespace
Persistence.SeedDatabase.MedicineForms
;
public
class
SeedMedicineForms
:
ISeed
<
MedicineForm
>
{
#
region
Ctor
DI
private
readonly
ClinicsDbContext
_clinicsContext
;
public
SeedMedicineForms
(
ClinicsDbContext
clinicsContext
)
{
_clinicsContext
=
clinicsContext
;
}
#
endregion
public
async
Task
Seed
()
{
DbSet
<
MedicineForm
>
medicineForms
=
_clinicsContext
.
Set
<
MedicineForm
>();
if
(
medicineForms
.
ToList
().
Count
!=
Domain
.
Entities
.
Medicals
.
Medicines
.
MedicineFormValues
.
MedicineForms
.
Count
)
{
medicineForms
.
RemoveRange
(
medicineForms
.
ToList
());
medicineForms
.
Add
(
Domain
.
Entities
.
Medicals
.
Medicines
.
MedicineFormValues
.
MedicineForms
.
Tablet
);
medicineForms
.
Add
(
Domain
.
Entities
.
Medicals
.
Medicines
.
MedicineFormValues
.
MedicineForms
.
Syrup
);
await
_clinicsContext
.
SaveChangesAsync
();
}
}
}
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