Commit ae1c806f authored by hasan khaddour's avatar hasan khaddour

implements the new repositories

parent 4a4eeb53
using System; using ApplicationDomain.Entities;
using Microsoft.AspNetCore.Identity;
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 +9,153 @@ using System.Threading.Tasks; ...@@ -6,7 +9,153 @@ using System.Threading.Tasks;
namespace Infrastructure.Data namespace Infrastructure.Data
{ {
class SeedDataContext public class SeedDataContext
{ {
public static ModelBuilder 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"
}
);
#endregion Roles
#region User
var ph = new PasswordHasher<IdentityUser>();
var admin = new User
{
Id = "1",
FirstName = "Hasan",
LastName = "Kh",
Avatar = "avatar.jpg",
Email = "hasan@b",
UserName = "Hasan.Bahjat",
PasswordHash = ph.HashPassword(null, "123@Aa"),
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.Bahjat",
CreationTime = DateTime.Now
};
var PatientAccount = new User
{
Id = "2",
FirstName = "Hasan",
LastName = "Khaddour",
Avatar = "avatar1.jpg",
Email = "hasan.bahjat@mail.y",
PasswordHash = ph.HashPassword(null, "123@Aa"),
UserName = "Hasan.Khaddour",
NormalizedEmail = "hasan@b",
NormalizedUserName = "Hasan.khaddour",
CreationTime = DateTime.Now
};
modelBuilder.Entity<User>()
.HasData(
admin,
PatientAccount
);
#endregion User
#region Patients
var Patient = new Patient
{
Id = 1,
BIO = "a Patient ",
UserId = PatientAccount.Id,
};
modelBuilder.Entity<Patient>().HasData(
Patient
);
#endregion Patients
#region Categories
var c1 = new Category { Id = 1, Name = "Antibiotic" };
var c2 = new Category { Id = 2, Name = "Painkiller" };
modelBuilder.Entity<Category>().HasData(
c1, c2
);
#endregion Categories
#region MedicineType
modelBuilder.Entity<MedicineType>().HasData(
new MedicineType { Id = 1, TypeName = "Tablet" },
new MedicineType { Id = 2, TypeName = "Syrup" }
);
#endregion MedicineType
#region Ingredients
modelBuilder.Entity<Ingredient>().HasData(
new Ingredient { Id = 1, Name = "Amoxicillin" },
new Ingredient { Id = 2, Name = "Paracetamol" }
);
#endregion Ingredients
#region Medicines
var med = new Medicine
{
Id = 1,
ScintificName = "Augmentine",
TradeName = "Augmentine",
Description = "antibitic mdicine",
ManufactureName = "Ibin Sina",
SideEffect = "No. ",
//Category=c1 ,
Image = "med1.png",
Dosage = 12,
Price = 2500,
};
// modelBuilder.Entity<MedicineIngredient>().HasData(
// new MedicineIngredient { Id = 1, MedicineId = 1, IngredientId = 1 },
// new MedicineIngredient { Id = 2, MedicineId = 2, IngredientId = 2 }
//);
modelBuilder.Entity<Medicine>().HasData(med);
#endregion Medicines
#region MedicalState
var st = new MedicalState
{
Id = 1,
PatientId = 1,
PrescriptionTime = DateTime.Now,
};
modelBuilder.Entity<MedicalState>().HasData(st);
#endregion MedicalState
return modelBuilder;
}
} }
} }
...@@ -16,6 +16,13 @@ namespace Infrastructure.UnitOfWork ...@@ -16,6 +16,13 @@ namespace Infrastructure.UnitOfWork
{ {
private readonly DbContext _context; private readonly DbContext _context;
private IGenericRepository<T> _entity; private IGenericRepository<T> _entity;
private IIngredientRepository _ingredients;
private IMedicalStateRepository _medicalStates;
private IPatientRepository _patients;
private IMedicineRepository _medicines;
public UnitOfWork(DbContext context) public UnitOfWork(DbContext context)
{ {
_context = context; _context = context;
...@@ -30,15 +37,55 @@ namespace Infrastructure.UnitOfWork ...@@ -30,15 +37,55 @@ namespace Infrastructure.UnitOfWork
return _entity ?? (_entity = new GenericRepository<T>(_context)); return _entity ?? (_entity = new GenericRepository<T>(_context));
} }
}
public IIngredientRepository Ingredients
{
get
{
return _ingredients ?? (_ingredients = new IngredientRepository(_context));
}
}
public IMedicalStateRepository MedicalStates
{
get
{
return _medicalStates ?? (_medicalStates = new MedicalStateRepository(_context));
}
}
public IPatientRepository Patients
{
get
{
return _patients ?? (_patients = new PatientRepository(_context));
}
} }
void IUnitOfWork<T>.Save() public IMedicineRepository Medicines
{
get
{
return _medicines ?? (_medicines = new MedicineRepository(_context));
}
}
public void Commit()
{ {
_context.SaveChanges(); _context.SaveChanges();
} }
public void RollBack() {
}
} }
} }
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