Commit 2f7b996d authored by hasan khaddour's avatar hasan khaddour

fix s

parent 2ce70ae7
......@@ -15,15 +15,15 @@ namespace Infrastructure.Data
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");
......@@ -70,44 +70,115 @@ namespace Infrastructure.Data
.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);
Seed(modelBuilder);
}
public void Seed(ModelBuilder modelBuilder) {
var P = new Patient
#region Roles
modelBuilder.Entity<IdentityRole>().HasData(
new IdentityRole
{
Name = "Admin",
NormalizedName = "Admin",
Id = "1-2-1"
},
new IdentityRole
{
Name = "patient",
NormalizedName = "patient",
Id = "1"
}
);
modelBuilder.Entity<IdentityUserRole<String>>()
.HasData( new IdentityUserRole<String>
{
UserId = "1",
RoleId = "1-2-1"
}, new IdentityUserRole<String>
{
UserId = "2",
RoleId = "1"
}
);
#endregion Roles
#region User
PasswordHasher<User> ph = new PasswordHasher<User>();
var admin = new User
{
Id = "1",
FirstName = "Hasan",
LastName = "Kh",
Avatar = "avatar.jpg",
Email = "hasan@b",
UserName="Hasan.Bahjat",
NormalizedEmail="hasan@b",
NormalizedUserName= "Hasan.Bahjat",
CreationTime = DateTime.Now
};
var PatientAccount = new User
{
Id = 1,
FirstName = "Hasasn",
Id = "2",
FirstName = "Hasan",
LastName = "Khaddour",
Avatar = "avatr.png"
Avatar = "avatar1.jpg",
Email = "hasan.bahjat@mail.y",
UserName = "Hasan.Khaddour",
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.khaddour",
CreationTime = DateTime.Now
};
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
admin.PasswordHash = ph.HashPassword(admin, "123@Aa");
PatientAccount.PasswordHash = ph.HashPassword(PatientAccount, "123@Aa");
modelBuilder.Entity<User>()
.HasData(
admin,
PatientAccount
);
#endregion User
#region Patients
var Patient = new Patient {
Id=1,
BIO = "a Patient ",
UserId = PatientAccount.Id,
};
//set user password
//appUser.Patient = P;
PasswordHasher<User> ph = new PasswordHasher<User>();
appUser.PasswordHash = ph.HashPassword(appUser, "123@Aa");
modelBuilder.Entity<Patient>().HasData(
Patient
);
//seed user
modelBuilder.Entity<User>().HasData(appUser);
#endregion Patients
#region Medicines
var med = new Medicine
{
Id=-1,
Name = "Augmentine",
Image="med1.png",
Dosage = 12,
Price = 2500,
};
var c = new Category { Id = 1, Name = "Augmentine" };
modelBuilder.Entity<Category>().HasData(c);
// med.Category = c;
modelBuilder.Entity<Medicine>().HasData(med);
#endregion Medicines
}
}
}
......@@ -21,4 +21,8 @@
<ProjectReference Include="..\ApplicationCore\ApplicationCore.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
// <auto-generated />
using System;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Infrastructure.Migrations
{
[DbContext(typeof(MedicDbContext))]
[Migration("20240521151453_initAuthAndDB")]
partial class initAuthAndDB
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:Collation", "Arabic_CI_AS")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.17")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("ApplicationCore.Entities.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("ApplicationCore.Entities.Ingredient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Ingredients");
});
modelBuilder.Entity("ApplicationCore.Entities.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int?>("CategoryId")
.HasColumnType("int");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<int>("Dosage")
.HasColumnType("int");
b.Property<int?>("MedicineTypeId")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int>("Price")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.HasIndex("MedicineTypeId");
b.ToTable("Medicines");
});
modelBuilder.Entity("ApplicationCore.Entities.MedicineIngredient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("IngredientId")
.HasColumnType("int");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("Ratio")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("IngredientId");
b.HasIndex("MedicineId");
b.ToTable("MedicineIngredient");
});
modelBuilder.Entity("ApplicationCore.Entities.MedicineType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("TypeName")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("MedicineTypes");
});
modelBuilder.Entity("ApplicationCore.Entities.Patient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Avatar")
.HasColumnType("nvarchar(max)");
b.Property<string>("BIO")
.HasColumnType("nvarchar(max)");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Patients");
});
modelBuilder.Entity("ApplicationCore.Entities.PatientMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<DateTime>("PrescripDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("PatientId");
b.ToTable("PatientMedicine");
});
modelBuilder.Entity("ApplicationCore.Entities.User", b =>
{
b.Property<string>("Id")
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetimeoffset");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("bit");
b.Property<string>("SecurityStamp")
.HasColumnType("nvarchar(max)");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("bit");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex")
.HasFilter("[NormalizedUserName] IS NOT NULL");
b.HasIndex("PatientId")
.IsUnique();
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex")
.HasFilter("[NormalizedName] IS NOT NULL");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("nvarchar(200)");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(200)");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderKey")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(200)");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("nvarchar(200)");
b.Property<string>("RoleId")
.HasColumnType("nvarchar(200)");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("nvarchar(200)");
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("Name")
.HasColumnType("nvarchar(450)");
b.Property<string>("Value")
.HasColumnType("nvarchar(max)");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("ApplicationCore.Entities.Medicine", b =>
{
b.HasOne("ApplicationCore.Entities.Category", "Category")
.WithMany("Medicines")
.HasForeignKey("CategoryId");
b.HasOne("ApplicationCore.Entities.MedicineType", "MedicineType")
.WithMany("Medicines")
.HasForeignKey("MedicineTypeId");
b.Navigation("Category");
b.Navigation("MedicineType");
});
modelBuilder.Entity("ApplicationCore.Entities.MedicineIngredient", b =>
{
b.HasOne("ApplicationCore.Entities.Ingredient", "Ingredient")
.WithMany("MedicineIngredients")
.HasForeignKey("IngredientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ApplicationCore.Entities.Medicine", "Medicine")
.WithMany("MedicineIngredients")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Ingredient");
b.Navigation("Medicine");
});
modelBuilder.Entity("ApplicationCore.Entities.PatientMedicine", b =>
{
b.HasOne("ApplicationCore.Entities.Medicine", "Medicine")
.WithMany("PatientMedicines")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ApplicationCore.Entities.Patient", "Patient")
.WithMany("PatientMedicines")
.HasForeignKey("PatientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Patient");
});
modelBuilder.Entity("ApplicationCore.Entities.User", b =>
{
b.HasOne("ApplicationCore.Entities.Patient", "Patient")
.WithOne("User")
.HasForeignKey("ApplicationCore.Entities.User", "PatientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Patient");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("ApplicationCore.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("ApplicationCore.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ApplicationCore.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("ApplicationCore.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ApplicationCore.Entities.Category", b =>
{
b.Navigation("Medicines");
});
modelBuilder.Entity("ApplicationCore.Entities.Ingredient", b =>
{
b.Navigation("MedicineIngredients");
});
modelBuilder.Entity("ApplicationCore.Entities.Medicine", b =>
{
b.Navigation("MedicineIngredients");
b.Navigation("PatientMedicines");
});
modelBuilder.Entity("ApplicationCore.Entities.MedicineType", b =>
{
b.Navigation("Medicines");
});
modelBuilder.Entity("ApplicationCore.Entities.Patient", b =>
{
b.Navigation("PatientMedicines");
b.Navigation("User");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace Infrastructure.Migrations
{
public partial class addMedicineImage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Image",
table: "Medicines",
type: "nvarchar(max)",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Image",
table: "Medicines");
}
}
}
......@@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Infrastructure.Migrations
{
[DbContext(typeof(MedicDbContext))]
[Migration("20240522121018_addMedicineImage")]
partial class addMedicineImage
[Migration("20240531143822_identityUpdat")]
partial class identityUpdat
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
......@@ -35,6 +35,13 @@ namespace Infrastructure.Migrations
b.HasKey("Id");
b.ToTable("Categories");
b.HasData(
new
{
Id = 1,
Name = "Augmentine"
});
});
modelBuilder.Entity("ApplicationCore.Entities.Ingredient", b =>
......@@ -90,6 +97,16 @@ namespace Infrastructure.Migrations
b.HasIndex("MedicineTypeId");
b.ToTable("Medicines");
b.HasData(
new
{
Id = -1,
Dosage = 12,
Image = "med1.png",
Name = "Augmentine",
Price = 2500
});
});
modelBuilder.Entity("ApplicationCore.Entities.MedicineIngredient", b =>
......@@ -139,21 +156,27 @@ namespace Infrastructure.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Avatar")
.HasColumnType("nvarchar(max)");
b.Property<string>("BIO")
.HasColumnType("nvarchar(max)");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.HasColumnType("nvarchar(200)");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique()
.HasFilter("[UserId] IS NOT NULL");
b.ToTable("Patients");
b.HasData(
new
{
Id = 1,
BIO = "a Patient ",
UserId = "2"
});
});
modelBuilder.Entity("ApplicationCore.Entities.PatientMedicine", b =>
......@@ -190,6 +213,9 @@ namespace Infrastructure.Migrations
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("Avatar")
.HasColumnType("nvarchar(max)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
......@@ -204,6 +230,12 @@ namespace Infrastructure.Migrations
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
......@@ -221,9 +253,6 @@ namespace Infrastructure.Migrations
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
......@@ -250,10 +279,49 @@ namespace Infrastructure.Migrations
.HasDatabaseName("UserNameIndex")
.HasFilter("[NormalizedUserName] IS NOT NULL");
b.HasIndex("PatientId")
.IsUnique();
b.ToTable("AspNetUsers");
b.HasData(
new
{
Id = "1",
AccessFailedCount = 0,
Avatar = "avatar.jpg",
ConcurrencyStamp = "9122e783-9528-4e0a-b15d-82345f6f0418",
CreationTime = new DateTime(2024, 5, 31, 17, 38, 21, 491, DateTimeKind.Local).AddTicks(4784),
Email = "hasan@b",
EmailConfirmed = false,
FirstName = "Hasan",
LastName = "Kh",
LockoutEnabled = false,
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.Bahjat",
PasswordHash = "AQAAAAEAACcQAAAAEJwazDmiC7dJqkx0ZQHpN6lKVdLp1MlBxIx4e5ZcqF+gkiJTfUb/OJOI6LYXXw8o2A==",
PhoneNumberConfirmed = false,
SecurityStamp = "3fe96d52-7dbf-46c8-b9ff-2bf6819fbeac",
TwoFactorEnabled = false,
UserName = "Hasan.Bahjat"
},
new
{
Id = "2",
AccessFailedCount = 0,
Avatar = "avatar1.jpg",
ConcurrencyStamp = "6ef31db3-4cc6-40c1-9082-3dca1d055c9a",
CreationTime = new DateTime(2024, 5, 31, 17, 38, 21, 508, DateTimeKind.Local).AddTicks(9726),
Email = "hasan.bahjat@mail.y",
EmailConfirmed = false,
FirstName = "Hasan",
LastName = "Khaddour",
LockoutEnabled = false,
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.khaddour",
PasswordHash = "AQAAAAEAACcQAAAAEDWozHY53JhRnMlp3wyKL2X6zVG8Rgd8AQSP7OHCui5ObaKA6p2dpcg6EVjXzMc99Q==",
PhoneNumberConfirmed = false,
SecurityStamp = "df27679f-e318-49b0-af02-2ebd01b2ef40",
TwoFactorEnabled = false,
UserName = "Hasan.Khaddour"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
......@@ -282,6 +350,22 @@ namespace Infrastructure.Migrations
.HasFilter("[NormalizedName] IS NOT NULL");
b.ToTable("AspNetRoles");
b.HasData(
new
{
Id = "1-2-1",
ConcurrencyStamp = "e90561ea-fc91-4e43-9090-6967145f6f5b",
Name = "Admin",
NormalizedName = "Admin"
},
new
{
Id = "1",
ConcurrencyStamp = "28134bcc-f733-40be-8d2e-bface932cc86",
Name = "patient",
NormalizedName = "patient"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
......@@ -367,6 +451,18 @@ namespace Infrastructure.Migrations
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
b.HasData(
new
{
UserId = "1",
RoleId = "1-2-1"
},
new
{
UserId = "2",
RoleId = "1"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
......@@ -422,6 +518,15 @@ namespace Infrastructure.Migrations
b.Navigation("Medicine");
});
modelBuilder.Entity("ApplicationCore.Entities.Patient", b =>
{
b.HasOne("ApplicationCore.Entities.User", "User")
.WithOne("Patient")
.HasForeignKey("ApplicationCore.Entities.Patient", "UserId");
b.Navigation("User");
});
modelBuilder.Entity("ApplicationCore.Entities.PatientMedicine", b =>
{
b.HasOne("ApplicationCore.Entities.Medicine", "Medicine")
......@@ -441,17 +546,6 @@ namespace Infrastructure.Migrations
b.Navigation("Patient");
});
modelBuilder.Entity("ApplicationCore.Entities.User", b =>
{
b.HasOne("ApplicationCore.Entities.Patient", "Patient")
.WithOne("User")
.HasForeignKey("ApplicationCore.Entities.User", "PatientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Patient");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
......@@ -528,8 +622,11 @@ namespace Infrastructure.Migrations
modelBuilder.Entity("ApplicationCore.Entities.Patient", b =>
{
b.Navigation("PatientMedicines");
});
b.Navigation("User");
modelBuilder.Entity("ApplicationCore.Entities.User", b =>
{
b.Navigation("Patient");
});
#pragma warning restore 612, 618
}
......
......@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Infrastructure.Migrations
{
public partial class initAuthAndDB : Migration
public partial class identityUpdat : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
......@@ -21,6 +21,35 @@ namespace Infrastructure.Migrations
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
Avatar = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
AccessFailedCount = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Categories",
columns: table => new
......@@ -62,40 +91,129 @@ namespace Infrastructure.Migrations
});
migrationBuilder.CreateTable(
name: "Patients",
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
Avatar = table.Column<string>(type: "nvarchar(max)", nullable: true),
BIO = table.Column<string>(type: "nvarchar(max)", nullable: true)
RoleId = table.Column<string>(type: "nvarchar(200)", nullable: false),
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Patients", x => x.Id);
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RoleId = table.Column<string>(type: "nvarchar(200)", nullable: false),
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false),
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false),
RoleId = table.Column<string>(type: "nvarchar(200)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false),
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Patients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<string>(type: "nvarchar(200)", nullable: true),
BIO = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Patients", x => x.Id);
table.ForeignKey(
name: "FK_Patients_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
......@@ -107,6 +225,7 @@ namespace Infrastructure.Migrations
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Price = table.Column<int>(type: "int", nullable: false),
Image = table.Column<string>(type: "nvarchar(max)", nullable: true),
Dosage = table.Column<int>(type: "int", nullable: false),
CategoryId = table.Column<int>(type: "int", nullable: true),
MedicineTypeId = table.Column<int>(type: "int", nullable: true)
......@@ -128,39 +247,6 @@ namespace Infrastructure.Migrations
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
PatientId = table.Column<int>(type: "int", nullable: false),
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
AccessFailedCount = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUsers_Patients_PatientId",
column: x => x.PatientId,
principalTable: "Patients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MedicineIngredient",
columns: table => new
......@@ -215,90 +301,48 @@ namespace Infrastructure.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false),
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
migrationBuilder.InsertData(
table: "AspNetRoles",
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
values: new object[,]
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
{ "1-2-1", "e90561ea-fc91-4e43-9090-6967145f6f5b", "Admin", "Admin" },
{ "1", "28134bcc-f733-40be-8d2e-bface932cc86", "patient", "patient" }
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false)
},
constraints: table =>
migrationBuilder.InsertData(
table: "AspNetUsers",
columns: new[] { "Id", "AccessFailedCount", "Avatar", "ConcurrencyStamp", "CreationTime", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
values: new object[,]
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
{ "1", 0, "avatar.jpg", "9122e783-9528-4e0a-b15d-82345f6f0418", new DateTime(2024, 5, 31, 17, 38, 21, 491, DateTimeKind.Local).AddTicks(4784), "hasan@b", false, "Hasan", "Kh", false, null, "hasan@b", "Hasan.Bahjat", "AQAAAAEAACcQAAAAEJwazDmiC7dJqkx0ZQHpN6lKVdLp1MlBxIx4e5ZcqF+gkiJTfUb/OJOI6LYXXw8o2A==", null, false, "3fe96d52-7dbf-46c8-b9ff-2bf6819fbeac", false, "Hasan.Bahjat" },
{ "2", 0, "avatar1.jpg", "6ef31db3-4cc6-40c1-9082-3dca1d055c9a", new DateTime(2024, 5, 31, 17, 38, 21, 508, DateTimeKind.Local).AddTicks(9726), "hasan.bahjat@mail.y", false, "Hasan", "Khaddour", false, null, "hasan@b", "Hasan.khaddour", "AQAAAAEAACcQAAAAEDWozHY53JhRnMlp3wyKL2X6zVG8Rgd8AQSP7OHCui5ObaKA6p2dpcg6EVjXzMc99Q==", null, false, "df27679f-e318-49b0-af02-2ebd01b2ef40", false, "Hasan.Khaddour" }
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false),
RoleId = table.Column<string>(type: "nvarchar(200)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Categories",
columns: new[] { "Id", "Name" },
values: new object[] { 1, "Augmentine" });
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "nvarchar(200)", nullable: false),
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Medicines",
columns: new[] { "Id", "CategoryId", "Description", "Dosage", "Image", "MedicineTypeId", "Name", "Price" },
values: new object[] { -1, null, null, 12, "med1.png", null, "Augmentine", 2500 });
migrationBuilder.InsertData(
table: "AspNetUserRoles",
columns: new[] { "RoleId", "UserId" },
values: new object[] { "1-2-1", "1" });
migrationBuilder.InsertData(
table: "AspNetUserRoles",
columns: new[] { "RoleId", "UserId" },
values: new object[] { "1", "2" });
migrationBuilder.InsertData(
table: "Patients",
columns: new[] { "Id", "BIO", "UserId" },
values: new object[] { 1, "a Patient ", "2" });
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
......@@ -332,12 +376,6 @@ namespace Infrastructure.Migrations
table: "AspNetUsers",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "IX_AspNetUsers_PatientId",
table: "AspNetUsers",
column: "PatientId",
unique: true);
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "AspNetUsers",
......@@ -374,6 +412,13 @@ namespace Infrastructure.Migrations
name: "IX_PatientMedicine_PatientId",
table: "PatientMedicine",
column: "PatientId");
migrationBuilder.CreateIndex(
name: "IX_Patients_UserId",
table: "Patients",
column: "UserId",
unique: true,
filter: "[UserId] IS NOT NULL");
}
protected override void Down(MigrationBuilder migrationBuilder)
......@@ -402,9 +447,6 @@ namespace Infrastructure.Migrations
migrationBuilder.DropTable(
name: "AspNetRoles");
migrationBuilder.DropTable(
name: "AspNetUsers");
migrationBuilder.DropTable(
name: "Ingredients");
......@@ -419,6 +461,9 @@ namespace Infrastructure.Migrations
migrationBuilder.DropTable(
name: "MedicineTypes");
migrationBuilder.DropTable(
name: "AspNetUsers");
}
}
}
......@@ -33,6 +33,13 @@ namespace Infrastructure.Migrations
b.HasKey("Id");
b.ToTable("Categories");
b.HasData(
new
{
Id = 1,
Name = "Augmentine"
});
});
modelBuilder.Entity("ApplicationCore.Entities.Ingredient", b =>
......@@ -88,6 +95,16 @@ namespace Infrastructure.Migrations
b.HasIndex("MedicineTypeId");
b.ToTable("Medicines");
b.HasData(
new
{
Id = -1,
Dosage = 12,
Image = "med1.png",
Name = "Augmentine",
Price = 2500
});
});
modelBuilder.Entity("ApplicationCore.Entities.MedicineIngredient", b =>
......@@ -137,21 +154,27 @@ namespace Infrastructure.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Avatar")
.HasColumnType("nvarchar(max)");
b.Property<string>("BIO")
.HasColumnType("nvarchar(max)");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.HasColumnType("nvarchar(200)");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique()
.HasFilter("[UserId] IS NOT NULL");
b.ToTable("Patients");
b.HasData(
new
{
Id = 1,
BIO = "a Patient ",
UserId = "2"
});
});
modelBuilder.Entity("ApplicationCore.Entities.PatientMedicine", b =>
......@@ -188,6 +211,9 @@ namespace Infrastructure.Migrations
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("Avatar")
.HasColumnType("nvarchar(max)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
......@@ -202,6 +228,12 @@ namespace Infrastructure.Migrations
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
......@@ -219,9 +251,6 @@ namespace Infrastructure.Migrations
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
......@@ -248,10 +277,49 @@ namespace Infrastructure.Migrations
.HasDatabaseName("UserNameIndex")
.HasFilter("[NormalizedUserName] IS NOT NULL");
b.HasIndex("PatientId")
.IsUnique();
b.ToTable("AspNetUsers");
b.HasData(
new
{
Id = "1",
AccessFailedCount = 0,
Avatar = "avatar.jpg",
ConcurrencyStamp = "9122e783-9528-4e0a-b15d-82345f6f0418",
CreationTime = new DateTime(2024, 5, 31, 17, 38, 21, 491, DateTimeKind.Local).AddTicks(4784),
Email = "hasan@b",
EmailConfirmed = false,
FirstName = "Hasan",
LastName = "Kh",
LockoutEnabled = false,
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.Bahjat",
PasswordHash = "AQAAAAEAACcQAAAAEJwazDmiC7dJqkx0ZQHpN6lKVdLp1MlBxIx4e5ZcqF+gkiJTfUb/OJOI6LYXXw8o2A==",
PhoneNumberConfirmed = false,
SecurityStamp = "3fe96d52-7dbf-46c8-b9ff-2bf6819fbeac",
TwoFactorEnabled = false,
UserName = "Hasan.Bahjat"
},
new
{
Id = "2",
AccessFailedCount = 0,
Avatar = "avatar1.jpg",
ConcurrencyStamp = "6ef31db3-4cc6-40c1-9082-3dca1d055c9a",
CreationTime = new DateTime(2024, 5, 31, 17, 38, 21, 508, DateTimeKind.Local).AddTicks(9726),
Email = "hasan.bahjat@mail.y",
EmailConfirmed = false,
FirstName = "Hasan",
LastName = "Khaddour",
LockoutEnabled = false,
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.khaddour",
PasswordHash = "AQAAAAEAACcQAAAAEDWozHY53JhRnMlp3wyKL2X6zVG8Rgd8AQSP7OHCui5ObaKA6p2dpcg6EVjXzMc99Q==",
PhoneNumberConfirmed = false,
SecurityStamp = "df27679f-e318-49b0-af02-2ebd01b2ef40",
TwoFactorEnabled = false,
UserName = "Hasan.Khaddour"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
......@@ -280,6 +348,22 @@ namespace Infrastructure.Migrations
.HasFilter("[NormalizedName] IS NOT NULL");
b.ToTable("AspNetRoles");
b.HasData(
new
{
Id = "1-2-1",
ConcurrencyStamp = "e90561ea-fc91-4e43-9090-6967145f6f5b",
Name = "Admin",
NormalizedName = "Admin"
},
new
{
Id = "1",
ConcurrencyStamp = "28134bcc-f733-40be-8d2e-bface932cc86",
Name = "patient",
NormalizedName = "patient"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
......@@ -365,6 +449,18 @@ namespace Infrastructure.Migrations
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
b.HasData(
new
{
UserId = "1",
RoleId = "1-2-1"
},
new
{
UserId = "2",
RoleId = "1"
});
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
......@@ -420,6 +516,15 @@ namespace Infrastructure.Migrations
b.Navigation("Medicine");
});
modelBuilder.Entity("ApplicationCore.Entities.Patient", b =>
{
b.HasOne("ApplicationCore.Entities.User", "User")
.WithOne("Patient")
.HasForeignKey("ApplicationCore.Entities.Patient", "UserId");
b.Navigation("User");
});
modelBuilder.Entity("ApplicationCore.Entities.PatientMedicine", b =>
{
b.HasOne("ApplicationCore.Entities.Medicine", "Medicine")
......@@ -439,17 +544,6 @@ namespace Infrastructure.Migrations
b.Navigation("Patient");
});
modelBuilder.Entity("ApplicationCore.Entities.User", b =>
{
b.HasOne("ApplicationCore.Entities.Patient", "Patient")
.WithOne("User")
.HasForeignKey("ApplicationCore.Entities.User", "PatientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Patient");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
......@@ -526,8 +620,11 @@ namespace Infrastructure.Migrations
modelBuilder.Entity("ApplicationCore.Entities.Patient", b =>
{
b.Navigation("PatientMedicines");
});
b.Navigation("User");
modelBuilder.Entity("ApplicationCore.Entities.User", b =>
{
b.Navigation("Patient");
});
#pragma warning restore 612, 618
}
......
using ApplicationCore.Entities;
using ApplicationCore.Interfaces;
using ApplicationCore.Interfaces.ISpecification;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
......@@ -25,30 +26,25 @@ namespace Infrastructure.Repository
_table.Remove(entity);
}
public IEnumerable<T> GetAll(params Expression<Func<T, object>>[] includeProperties)
public IEnumerable<T> GetAll(ISpecification<T> specification)
{
{
IQueryable<T> queryable = _table;
foreach (var includeProperty in includeProperties)
{
queryable = queryable.Include(includeProperty);
}
queryable = GetQuery(queryable, specification);
return queryable.AsEnumerable();
}
}
public T GetById(int id, params Expression<Func<T, object>>[] includeProperties)
public T GetById(int id, ISpecification<T>? specification)
{
IQueryable<T> query = _table;
if (includeProperties is not null)
foreach (var includeProperty in includeProperties)
{
query = query.Include(includeProperty);
}
return query.Where(p => p.Id == id).First();
if(specification != null )
query = GetQuery(query, specification);
return query.Where(p => p.Id == id).FirstOrDefault();
}
public T Insert(T entity)
......@@ -63,5 +59,35 @@ namespace Infrastructure.Repository
return e;
}
public IQueryable<T> GetQuery(IQueryable<T> inputQuery, ISpecification<T> specification)
{
IQueryable<T> query = inputQuery;
// modify the IQueryable using the specification's criteria expression
if (specification.Criteria != null)
{
query = query.Where(specification.Criteria);
}
// Includes all expression-based includes
query = specification.Includes.Aggregate(query,
(current, include) => current.Include(include));
// Include any string-based include statements
query = specification.ThenInclude.Aggregate(query,
(current, include) => current.Include(include));
// Apply ordering if expressions are set
if (specification.OrderBy != null)
{
query = query.OrderBy(specification.OrderBy);
}
else if (specification.OrderByDescending != null)
{
query = query.OrderByDescending(specification.OrderByDescending);
}
return query;
}
}
}
16668239acb0b8ba1b3fb234af1679c89ab8ecd0
86b4a36b27ca89275e50461b3805a94292ff7dbf
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment