Это не костыль, это уже реально инвалидная коляска. Если это фикс сломал мне работу с постгресом, я повешусь

This commit is contained in:
frog24 2024-05-20 04:55:24 +04:00
parent ee5464553a
commit 6d0b54541c
3 changed files with 35 additions and 1 deletions

View File

@ -53,6 +53,7 @@ namespace DepartmentStaffDatabase
}
public class Employee_Course
{
public int? Id { get; set; }
[BsonRepresentation(BsonType.Int32)]
public int EmployeeId { get; set; }
[BsonRepresentation(BsonType.Int32)]

View File

@ -235,6 +235,12 @@ namespace DepartmentStaffDatabase
public override void CreateEmployee_Course(Employee_Course employee_course)
{
var maxId = 0;
if (GetEmployee_Courses().Count > 0)
{
maxId = _employee_CourseCollection.AsQueryable().Max(crs => crs.Id).Value;
}
employee_course.Id = maxId + 1;
_employee_CourseCollection.InsertOne(employee_course);
}
public override void DeleteEmployee_Course(int empId, int courseId)
@ -247,7 +253,21 @@ namespace DepartmentStaffDatabase
}
public override List<Employee_Course> GetEmployee_Courses()
{
return _employee_CourseCollection.Find(_ => true).ToList();
var employee_CourseList = _employee_CourseCollection.Find(_ => true).ToList();
var resultList = new List<Employee_Course>();
foreach (var employee_Course in employee_CourseList)
{
resultList.Add(new Employee_Course
{
Id = employee_Course.Id,
EmployeeId = employee_Course.EmployeeId,
CourseId = employee_Course.CourseId
});
}
return resultList;
}
public override void DeleteEmployee_Courses()
{

View File

@ -24,7 +24,20 @@ namespace DepartmentStaffView
{
try
{
if (dataGridView1.ColumnCount == 0)
{
dataGridView1.Columns.Add("EmployeeId", "EmployeeId");
dataGridView1.Columns.Add("CourseId", "CourseId");
}
var list = db.GetEmployee_Courses();
if (list != null)
{
dataGridView1.Rows.Clear();
foreach (var el in list)
{
dataGridView1.Rows.Add(el.EmployeeId, el.CourseId);
}
}
}
catch (Exception ex)
{