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

fix s

parent 2ce70ae7
......@@ -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);
base.OnModelCreating(modelBuilder);
// Seed(modelBuilder);
Seed(modelBuilder);
base.OnModelCreating(modelBuilder);
}
public void Seed(ModelBuilder modelBuilder) {
#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"
}
public void Seed(ModelBuilder modelBuilder) {
var P = new Patient
);
#endregion Roles
#region User
PasswordHasher<User> ph = new PasswordHasher<User>();
var admin = new User
{
Id = 1,
FirstName = "Hasasn",
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 = "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
);
#endregion Patients
#region Medicines
var med = new Medicine
{
Id=-1,
Name = "Augmentine",
Image="med1.png",
Dosage = 12,
Price = 2500,
//seed user
modelBuilder.Entity<User>().HasData(appUser);
};
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>
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");
}
}
}
......@@ -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