Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Medic
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
Medic
Commits
a4ff3589
Commit
a4ff3589
authored
May 21, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update db context
parent
9b475700
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
3 deletions
+104
-3
MedicDbContext.cs
Infrastructure/Data/MedicDbContext.cs
+104
-3
No files found.
Infrastructure/Data/MedicDbContext.cs
View file @
a4ff3589
using
System
;
using
ApplicationCore.Entities
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Identity.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
...
@@ -6,7 +10,104 @@ using System.Threading.Tasks;
...
@@ -6,7 +10,104 @@ using System.Threading.Tasks;
namespace
Infrastructure.Data
namespace
Infrastructure.Data
{
{
class
MedicDbContext
public
class
MedicDbContext
:
IdentityDbContext
<
User
>
{
{
public
MedicDbContext
(
DbContextOptions
<
MedicDbContext
>
options
)
:
base
(
options
)
{
}
public
DbSet
<
Patient
>
Patients
{
get
;
set
;
}
public
DbSet
<
Medicine
>
Medicines
{
get
;
set
;
}
public
DbSet
<
Ingredient
>
Ingredients
{
get
;
set
;
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
public
DbSet
<
MedicineType
>
MedicineTypes
{
get
;
set
;
}
protected
override
void
OnConfiguring
(
DbContextOptionsBuilder
optionsBuilder
)
{
optionsBuilder
.
UseSqlServer
(
"Data Source=DESKTOP-TI6EF1L\\SQLEXPRESS;Initial Catalog=portfoilo;Integrated Security=True"
);
}
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
base
.
OnModelCreating
(
modelBuilder
);
modelBuilder
.
HasAnnotation
(
"Relational:Collation"
,
"Arabic_CI_AS"
);
modelBuilder
.
Entity
<
Medicine
>()
.
HasMany
(
e
=>
e
.
Ingredients
)
.
WithMany
(
e
=>
e
.
Medicines
)
.
UsingEntity
<
MedicineIngredient
>(
l
=>
l
.
HasOne
<
Ingredient
>(
e
=>
e
.
Ingredient
)
.
WithMany
(
e
=>
e
.
MedicineIngredients
)
.
HasForeignKey
(
e
=>
e
.
IngredientId
),
r
=>
r
.
HasOne
<
Medicine
>(
e
=>
e
.
Medicine
)
.
WithMany
(
e
=>
e
.
MedicineIngredients
)
.
HasForeignKey
(
e
=>
e
.
MedicineId
)
);
modelBuilder
.
Entity
<
Patient
>()
.
HasMany
(
e
=>
e
.
Medicines
)
.
WithMany
(
e
=>
e
.
Patients
)
.
UsingEntity
<
PatientMedicine
>(
l
=>
l
.
HasOne
<
Medicine
>(
e
=>
e
.
Medicine
)
.
WithMany
(
e
=>
e
.
PatientMedicines
)
.
HasForeignKey
(
e
=>
e
.
MedicineId
),
r
=>
r
.
HasOne
<
Patient
>(
e
=>
e
.
Patient
)
.
WithMany
(
e
=>
e
.
PatientMedicines
)
.
HasForeignKey
(
e
=>
e
.
PatientId
)
);
modelBuilder
.
Entity
<
Patient
>()
.
HasOne
(
o
=>
o
.
User
);
modelBuilder
.
Entity
<
Medicine
>()
.
HasOne
(
o
=>
o
.
Category
)
;
modelBuilder
.
Entity
<
Medicine
>()
.
HasOne
(
o
=>
o
.
MedicineType
);
modelBuilder
.
Entity
<
User
>().
Property
(
e
=>
e
.
Id
).
HasMaxLength
(
200
);
modelBuilder
.
Entity
<
IdentityRole
>().
Property
(
e
=>
e
.
Id
).
HasMaxLength
(
200
);
// Seed(modelBuilder);
base
.
OnModelCreating
(
modelBuilder
);
}
public
void
Seed
(
ModelBuilder
modelBuilder
)
{
var
P
=
new
Patient
{
Id
=
1
,
FirstName
=
"Hasasn"
,
LastName
=
"Khaddour"
,
Avatar
=
"avatr.png"
};
modelBuilder
.
Entity
<
Patient
>().
HasData
(
P
);
var
appUser
=
new
User
{
Id
=
"123-1213"
,
Email
=
"hasan@b"
,
EmailConfirmed
=
true
,
UserName
=
"frankofoedu@gmail.com"
,
NormalizedUserName
=
"FRANKOFOEDU@GMAIL.COM"
,
PatientId
=
1
};
//set user password
//appUser.Patient = P;
PasswordHasher
<
User
>
ph
=
new
PasswordHasher
<
User
>();
appUser
.
PasswordHash
=
ph
.
HashPassword
(
appUser
,
"123@Aa"
);
//seed user
modelBuilder
.
Entity
<
User
>().
HasData
(
appUser
);
}
}
}
}
}
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