Commit 157eceaa authored by hasan khaddour's avatar hasan khaddour

some updates

parent da9d0201
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using PSManagement.Domain.Customers.Aggregate; using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Employees.Entities; using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Identity.Entities; using PSManagement.Domain.Identity.Entities;
using PSManagement.Domain.Projects.Entities; using PSManagement.Domain.Projects.Entities;
......
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using PSManagement.Domain.Customers.Repositories; using PSManagement.Domain.Customers.Repositories;
using PSManagement.Domain.Employees.Repositories;
using PSManagement.Domain.Identity.Repositories; using PSManagement.Domain.Identity.Repositories;
using PSManagement.Domain.Projects.Builders;
using PSManagement.Domain.Projects.Repositories; using PSManagement.Domain.Projects.Repositories;
using PSManagement.Infrastructure.Persistence.Repositories.CustomerRepository; using PSManagement.Infrastructure.Persistence.Repositories.CustomerRepository;
using PSManagement.Infrastructure.Persistence.Repositories.EmployeeRepository;
using PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository; using PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository;
using PSManagement.Infrastructure.Persistence.Repositories.UserRepository; using PSManagement.Infrastructure.Persistence.Repositories.UserRepository;
using PSManagement.Infrastructure.Persistence.UoW; using PSManagement.Infrastructure.Persistence.UoW;
...@@ -23,9 +26,11 @@ namespace PSManagement.Infrastructure.Persistence.DI ...@@ -23,9 +26,11 @@ namespace PSManagement.Infrastructure.Persistence.DI
services.AddScoped<IUsersRepository, UsersRepository>(); services.AddScoped<IUsersRepository, UsersRepository>();
services.AddScoped<ICustomersRepository, CustomersReposiotry>(); services.AddScoped<ICustomersRepository, CustomersReposiotry>();
services.AddScoped<IProjectsRepository, ProjectsRepository>(); services.AddScoped<IProjectsRepository, ProjectsRepository>();
services.AddScoped<IRolesRepository, RolesRepository>();
services.AddScoped<IEmployeesRepository, EmployeesRespository>();
services.AddScoped<ProjectBuilder>();
services.AddScoped<IUnitOfWork, UnitOfWork>(); services.AddScoped<IUnitOfWork, UnitOfWork>();
return services; return services;
} }
......
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PSManagement.Domain.Customers.Aggregate; using PSManagement.Domain.Customers.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
......
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PSManagement.Domain.Employees.Entities; using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Identity.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -9,7 +10,7 @@ using System.Threading.Tasks; ...@@ -9,7 +10,7 @@ using System.Threading.Tasks;
namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
{ {
public class EmployeeEntityConfiguration : IEntityTypeConfiguration<Employee> public class EmployeeEntityConfiguration : IEntityTypeConfiguration<Employee> ,IEntityTypeConfiguration<User>
{ {
public void Configure(EntityTypeBuilder<Employee> builder) public void Configure(EntityTypeBuilder<Employee> builder)
{ {
...@@ -41,5 +42,17 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration ...@@ -41,5 +42,17 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
} }
public void Configure(EntityTypeBuilder<User> builder)
{
builder
.HasMany(u => u.Roles)
.WithMany(r => r.Users)
.UsingEntity<Dictionary<string, object>>(
"UserRole",
j => j.HasOne<Role>().WithMany().HasForeignKey("RoleId"),
j => j.HasOne<User>().WithMany().HasForeignKey("UserId")
);
}
} }
} }
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class SeedData : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class SeedData1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RoleUser");
migrationBuilder.CreateTable(
name: "UserRole",
columns: table => new
{
RoleId = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserRole", x => new { x.RoleId, x.UserId });
table.ForeignKey(
name: "FK_UserRole_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_UserRole_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Roles",
columns: new[] { "Id", "Name" },
values: new object[,]
{
{ 1, "Admin" },
{ 2, "Employee" },
{ 3, "Scientific-Supervisor" }
});
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "Email", "HashedPassword", "UserName" },
values: new object[] { 1210, "Admin@Admin", "1234", "Admin" });
migrationBuilder.InsertData(
table: "UserRole",
columns: new[] { "RoleId", "UserId" },
values: new object[] { 1, 1210 });
migrationBuilder.CreateIndex(
name: "IX_UserRole_UserId",
table: "UserRole",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserRole");
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: 3);
migrationBuilder.DeleteData(
table: "Users",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.CreateTable(
name: "RoleUser",
columns: table => new
{
RolesId = table.Column<int>(type: "int", nullable: false),
UsersId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RoleUser", x => new { x.RolesId, x.UsersId });
table.ForeignKey(
name: "FK_RoleUser_Roles_RolesId",
column: x => x.RolesId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RoleUser_Users_UsersId",
column: x => x.UsersId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_RoleUser_UsersId",
table: "RoleUser",
column: "UsersId");
}
}
}
...@@ -119,6 +119,23 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -119,6 +119,23 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Roles"); b.ToTable("Roles");
b.HasData(
new
{
Id = 1,
Name = "Admin"
},
new
{
Id = 2,
Name = "Employee"
},
new
{
Id = 3,
Name = "Scientific-Supervisor"
});
}); });
modelBuilder.Entity("PSManagement.Domain.Identity.Entities.User", b => modelBuilder.Entity("PSManagement.Domain.Identity.Entities.User", b =>
...@@ -140,6 +157,15 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -140,6 +157,15 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Users"); b.ToTable("Users");
b.HasData(
new
{
Id = 2,
Email = "Admin@Admin",
HashedPassword = "1234",
UserName = "Admin"
});
}); });
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.Attachment", b => modelBuilder.Entity("PSManagement.Domain.Projects.Entities.Attachment", b =>
...@@ -417,19 +443,26 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -417,19 +443,26 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.ToTable("PermissionRole"); b.ToTable("PermissionRole");
}); });
modelBuilder.Entity("RoleUser", b => modelBuilder.Entity("UserRole", b =>
{ {
b.Property<int>("RolesId") b.Property<int>("RoleId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("UsersId") b.Property<int>("UserId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("RolesId", "UsersId"); b.HasKey("RoleId", "UserId");
b.HasIndex("UserId");
b.HasIndex("UsersId"); b.ToTable("UserRole");
b.ToTable("RoleUser"); b.HasData(
new
{
RoleId = 1,
UserId = 1
});
}); });
modelBuilder.Entity("PSManagement.Domain.Customers.Aggregate.Customer", b => modelBuilder.Entity("PSManagement.Domain.Customers.Aggregate.Customer", b =>
...@@ -870,17 +903,17 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -870,17 +903,17 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("RoleUser", b => modelBuilder.Entity("UserRole", b =>
{ {
b.HasOne("PSManagement.Domain.Identity.Entities.Role", null) b.HasOne("PSManagement.Domain.Identity.Entities.Role", null)
.WithMany() .WithMany()
.HasForeignKey("RolesId") .HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("PSManagement.Domain.Identity.Entities.User", null) b.HasOne("PSManagement.Domain.Identity.Entities.User", null)
.WithMany() .WithMany()
.HasForeignKey("UsersId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
......
using PSManagement.Domain.Customers.Aggregate; using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Customers.Repositories; using PSManagement.Domain.Customers.Repositories;
using PSManagement.Infrastructure.Persistence.Repositories.Base; using PSManagement.Infrastructure.Persistence.Repositories.Base;
using System; using System;
......
using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Employees.Repositories;
using PSManagement.Infrastructure.Persistence.Repositories.Base;
namespace PSManagement.Infrastructure.Persistence.Repositories.EmployeeRepository
{
public class EmployeesRespository : BaseRepository<Employee>, IEmployeesRepository
{
public EmployeesRespository(AppDbContext context) : base(context)
{
}
}
}
using PSManagement.Domain.Projects.Repositories; using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.Infrastructure.Persistence.Repositories.Base;
using PSManagement.SharedKernel.Repositories;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -7,7 +10,10 @@ using System.Threading.Tasks; ...@@ -7,7 +10,10 @@ using System.Threading.Tasks;
namespace PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository namespace PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository
{ {
public class ProjectsRepository :IProjectsRepository public class ProjectsRepository : BaseRepository<Project> , IProjectsRepository
{ {
public ProjectsRepository(AppDbContext context) : base(context)
{
}
} }
} }
...@@ -29,4 +29,18 @@ namespace PSManagement.Infrastructure.Persistence.Repositories.UserRepository ...@@ -29,4 +29,18 @@ namespace PSManagement.Infrastructure.Persistence.Repositories.UserRepository
} }
public class RolesRepository : BaseRepository<Role>, IRolesRepository
{
public RolesRepository(AppDbContext context) : base(context)
{
}
public async Task<Role> GetByRoleName(string roleName, ISpecification<Role> specification = null)
{
IEnumerable<Role> roles = await this.ListAsync(specification);
return roles.FirstOrDefault(r => r.Name == roleName);
}
}
} }
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PSManagement.Domain.Employees.Entities; using PSManagement.Domain.Employees.Entities;
using PSManagement.Domain.Identity.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -14,6 +15,8 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext ...@@ -14,6 +15,8 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext
public static Task SeedAsync(ModelBuilder builder) public static Task SeedAsync(ModelBuilder builder)
{ {
SeedDepartments(builder); SeedDepartments(builder);
SeedAdmin(builder);
SeedRoles(builder);
return Task.CompletedTask; return Task.CompletedTask;
} }
public static void SeedDepartments(ModelBuilder builder) { public static void SeedDepartments(ModelBuilder builder) {
...@@ -27,6 +30,29 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext ...@@ -27,6 +30,29 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext
) ; ) ;
} }
public static void SeedRoles(ModelBuilder builder)
{
builder.Entity<Role>().HasData(
new Role {Id=1, Name = "Admin" },
new Role {Id = 2, Name = "Employee" },
new Role {Id = 3, Name = "Scientific-Supervisor" }
);
}
public static void SeedAdmin(ModelBuilder builder)
{
builder.Entity<User>().HasData(
new User { Id = 2, UserName = "Admin" ,Email="Admin@Admin",HashedPassword="1234" }
);
builder.Entity("UserRole").HasData(
new Dictionary<string, object> { ["UserId"] = 1, ["RoleId"] = 1 }
);
}
} }
} }
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