Commit 3604a56e authored by hasan khaddour's avatar hasan khaddour

implemnt some services

parent 16f4443d
......@@ -40,6 +40,7 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
.HasForeignKey<Employee>(e => e.UserId); ;
builder.HasOne(e => e.Department).WithMany().OnDelete(DeleteBehavior.Restrict).IsRequired(false);
}
......
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class ADDDepartmentToEmployeee : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: 3);
migrationBuilder.AddColumn<int>(
name: "DepartmentId",
table: "Employees",
type: "int",
nullable: true);
migrationBuilder.UpdateData(
table: "Departments",
keyColumn: "Id",
keyValue: 2,
column: "Name",
value: "قسم النظم الإلكترونية");
migrationBuilder.UpdateData(
table: "Departments",
keyColumn: "Id",
keyValue: 3,
column: "Name",
value: "قسم الميكاترونيكس");
migrationBuilder.InsertData(
table: "Departments",
columns: new[] { "Id", "Name" },
values: new object[,]
{
{ 4, "قسم الفيزياء" },
{ 5, "مديرية التطوير والخدمات البرمجية" },
{ 6, "شؤون الطلاب" }
});
migrationBuilder.InsertData(
table: "Roles",
columns: new[] { "Id", "Name" },
values: new object[] { 4, "Scientific-Deputy" });
migrationBuilder.CreateIndex(
name: "IX_Employees_DepartmentId",
table: "Employees",
column: "DepartmentId");
migrationBuilder.AddForeignKey(
name: "FK_Employees_Departments_DepartmentId",
table: "Employees",
column: "DepartmentId",
principalTable: "Departments",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Employees_Departments_DepartmentId",
table: "Employees");
migrationBuilder.DropIndex(
name: "IX_Employees_DepartmentId",
table: "Employees");
migrationBuilder.DeleteData(
table: "Departments",
keyColumn: "Id",
keyValue: 4);
migrationBuilder.DeleteData(
table: "Departments",
keyColumn: "Id",
keyValue: 5);
migrationBuilder.DeleteData(
table: "Departments",
keyColumn: "Id",
keyValue: 6);
migrationBuilder.DeleteData(
table: "Roles",
keyColumn: "Id",
keyValue: 4);
migrationBuilder.DropColumn(
name: "DepartmentId",
table: "Employees");
migrationBuilder.UpdateData(
table: "Departments",
keyColumn: "Id",
keyValue: 2,
column: "Name",
value: "قسم النظم الإلكترونيى");
migrationBuilder.UpdateData(
table: "Departments",
keyColumn: "Id",
keyValue: 3,
column: "Name",
value: "شؤون الطلاب");
migrationBuilder.InsertData(
table: "Roles",
columns: new[] { "Id", "Name" },
values: new object[] { 3, "Scientific-Supervisor" });
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class AddDepartmentToEmployeee1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "DepartmentId",
table: "Employees",
type: "int",
nullable: true,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "DepartmentId",
table: "Employees",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class UpdateTrackEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsCompleted",
table: "Tracks",
type: "bit",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsCompleted",
table: "Tracks");
}
}
}
......@@ -61,11 +61,26 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
new
{
Id = 2,
Name = "قسم النظم الإلكترونيى"
Name = "قسم النظم الإلكترونية"
},
new
{
Id = 3,
Name = "قسم الميكاترونيكس"
},
new
{
Id = 4,
Name = "قسم الفيزياء"
},
new
{
Id = 5,
Name = "مديرية التطوير والخدمات البرمجية"
},
new
{
Id = 6,
Name = "شؤون الطلاب"
});
});
......@@ -77,6 +92,9 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<int>("DepartmentId")
.HasColumnType("int");
b.Property<int>("HIASTId")
.HasColumnType("int");
......@@ -85,12 +103,43 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.HasKey("Id");
b.HasIndex("DepartmentId");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("Employees");
});
modelBuilder.Entity("PSManagement.Domain.FinancialSpends.Entities.FinancialSpending", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("CostType")
.HasColumnType("nvarchar(max)");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ExpectedSpendingDate")
.HasColumnType("datetime2");
b.Property<int>("LocalPurchase")
.HasColumnType("int");
b.Property<int?>("ProjectId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("FinancialSpending");
});
modelBuilder.Entity("PSManagement.Domain.Identity.Entities.Permission", b =>
{
b.Property<int>("Id")
......@@ -133,8 +182,8 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
},
new
{
Id = 3,
Name = "Scientific-Supervisor"
Id = 4,
Name = "Scientific-Deputy"
});
});
......@@ -222,35 +271,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.ToTable("EmployeeParticipate");
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.FinancialSpending", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("CostType")
.HasColumnType("nvarchar(max)");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ExpectedSpendingDate")
.HasColumnType("datetime2");
b.Property<int>("LocalPurchase")
.HasColumnType("int");
b.Property<int?>("ProjectId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("FinancialSpending");
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.Project", b =>
{
b.Property<int>("Id")
......@@ -471,6 +491,9 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("IsCompleted")
.HasColumnType("bit");
b.Property<int>("ProjectId")
.HasColumnType("int");
......@@ -603,6 +626,11 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
modelBuilder.Entity("PSManagement.Domain.Employees.Entities.Employee", b =>
{
b.HasOne("PSManagement.Domain.Employees.Entities.Department", "Department")
.WithMany()
.HasForeignKey("DepartmentId")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("PSManagement.Domain.Identity.Entities.User", "User")
.WithOne("Employee")
.HasForeignKey("PSManagement.Domain.Employees.Entities.Employee", "UserId")
......@@ -680,6 +708,8 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.Navigation("Availability");
b.Navigation("Department");
b.Navigation("PersonalInfo");
b.Navigation("User");
......@@ -687,35 +717,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.Navigation("WorkInfo");
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.Attachment", b =>
{
b.HasOne("PSManagement.Domain.Projects.Entities.Project", null)
.WithMany("Attachments")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.EmployeeParticipate", b =>
{
b.HasOne("PSManagement.Domain.Employees.Entities.Employee", "Employee")
.WithMany("EmployeeParticipates")
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PSManagement.Domain.Projects.Entities.Project", "Project")
.WithMany("EmployeeParticipates")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Employee");
b.Navigation("Project");
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.FinancialSpending", b =>
modelBuilder.Entity("PSManagement.Domain.FinancialSpends.Entities.FinancialSpending", b =>
{
b.HasOne("PSManagement.Domain.Projects.Entities.Project", null)
.WithMany("FinancialSpending")
......@@ -749,6 +751,34 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.Navigation("ExternalPurchase");
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.Attachment", b =>
{
b.HasOne("PSManagement.Domain.Projects.Entities.Project", null)
.WithMany("Attachments")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.EmployeeParticipate", b =>
{
b.HasOne("PSManagement.Domain.Employees.Entities.Employee", "Employee")
.WithMany("EmployeeParticipates")
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PSManagement.Domain.Projects.Entities.Project", "Project")
.WithMany("EmployeeParticipates")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Employee");
b.Navigation("Project");
});
modelBuilder.Entity("PSManagement.Domain.Projects.Entities.Project", b =>
{
b.HasOne("PSManagement.Domain.Customers.Entities.Customer", null)
......
......@@ -23,8 +23,11 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext
builder.Entity<Department>().HasData(
new Department { Id = 1, Name = "قسم المعلوميات" },
new Department { Id = 2, Name = "قسم النظم الإلكترونيى" },
new Department { Id = 3, Name = "شؤون الطلاب" }
new Department { Id = 2, Name = "قسم النظم الإلكترونية" },
new Department { Id = 3, Name = "قسم الميكاترونيكس" },
new Department { Id = 4, Name = "قسم الفيزياء" },
new Department { Id = 5, Name = "مديرية التطوير والخدمات البرمجية" },
new Department { Id = 6, Name = "شؤون الطلاب" }
) ;
......@@ -34,10 +37,9 @@ namespace PSManagement.Infrastructure.Persistence.SeedDataContext
{
builder.Entity<Role>().HasData(
new Role {Id=1, Name = "Admin" },
new Role {Id = 2, Name = "Employee" },
new Role {Id = 3, Name = "Scientific-Supervisor" }
new Role {Id = 4, Name = "Scientific-Deputy" }
);
......
......@@ -12,7 +12,10 @@ namespace PSManagement.Infrastructure.Services.Providers
private readonly static List<Employee> _employees = new()
{
new Employee { Availability = new Availability(0, true), PersonalInfo = new PersonalInfo("Hasan", "Khaddour"), HIASTId = 1, User = new User { UserName = "Hasan@mail.hiast", Email = "Hasan@mail.hiast" }, WorkInfo = new WorkInfo("Researcher", "Worker") }
new Employee { Availability = new Availability(0, true), PersonalInfo = new PersonalInfo("Hasan", "Khaddour"), HIASTId = 1, User = new User { UserName = "Hasan@mail.hiast", Email = "Hasan@mail.hiast",HashedPassword="1234" },DepartmentId=1, WorkInfo = new WorkInfo("Researcher", "Worker") },
new Employee { Availability = new Availability(0, true), PersonalInfo = new PersonalInfo("Mhd", "hasan"), HIASTId = 5, User = new User { UserName = "mhd@mail.hiast", Email = "mhd@mail.hiast", HashedPassword = "1234" }, DepartmentId = 1, WorkInfo = new WorkInfo("worker", "Worker") },
new Employee { Availability = new Availability(0, true), PersonalInfo = new PersonalInfo("mahmoud", "hasan"), HIASTId = 6, User = new User { UserName = "mahmoud@mail.hiast", Email = "mahmoud@mail.hiast", HashedPassword = "1234" }, DepartmentId = 2, WorkInfo = new WorkInfo("worker", "Worker") },
new Employee { Availability = new Availability(0, true), PersonalInfo = new PersonalInfo("ali", "ahmad"), HIASTId = 8, User = new User { UserName = "rawad@mail.hiast", Email = "rawad@mail.hiast", HashedPassword = "1234" }, DepartmentId = 2, WorkInfo = new WorkInfo("worker", "Worker") }
};
public Task<IEnumerable<Employee>> FetchEmployees()
......
......@@ -14,6 +14,7 @@ using PSManagement.Domain.Employees.Repositories;
using PSManagement.Domain.Employees.Entities;
using PSManagement.SharedKernel.Specification;
using PSManagement.Domain.Employees.Specification;
using PSManagement.Application.Contracts.Authorization;
namespace PSManagement.Infrastructure.BackgroundServcies
{
......@@ -24,18 +25,20 @@ namespace PSManagement.Infrastructure.BackgroundServcies
private readonly IEmployeesProvider _employeesProviders;
private readonly BaseSpecification<Employee> _specification;
private readonly IDateTimeProvider _timeProvider;
private readonly IUserRoleService _userRoleService;
public SyncEmployeesService(
IEmployeesRepository employeesRepository,
IEmployeesProvider employeesProviders,
IDateTimeProvider timeProvider
)
IDateTimeProvider timeProvider,
IUserRoleService userRoleService)
{
_employeesRepository = employeesRepository;
_employeesProviders = employeesProviders;
_specification = new EmployeesSpecification();
_timeProvider = timeProvider;
_userRoleService = userRoleService;
}
public async Task<SyncResponse> SyncEmployees(IEmployeesProvider employeesProvider)
......@@ -47,7 +50,9 @@ namespace PSManagement.Infrastructure.BackgroundServcies
_specification.Criteria = empl => empl.HIASTId == employee.HIASTId;
Employee emp = _employeesRepository.ListAsync(_specification).Result.FirstOrDefault();
if (emp is null) {
await _employeesRepository.AddAsync(employee);
emp =await _employeesRepository.AddAsync(employee);
await _userRoleService.AssignUserToRole(emp.User.Email,"Employee");
count++;
}
......
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