diff --git a/DepartmentStaffView/DepartmentStaffDatabase/Models.cs b/DepartmentStaffView/DepartmentStaffDatabase/Models.cs index 4704774..a765d2c 100644 --- a/DepartmentStaffView/DepartmentStaffDatabase/Models.cs +++ b/DepartmentStaffView/DepartmentStaffDatabase/Models.cs @@ -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)] diff --git a/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs b/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs index 864ab5e..ba45499 100644 --- a/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs +++ b/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs @@ -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 GetEmployee_Courses() { - return _employee_CourseCollection.Find(_ => true).ToList(); + var employee_CourseList = _employee_CourseCollection.Find(_ => true).ToList(); + + var resultList = new List(); + + 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() { diff --git a/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs b/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs index d95cc36..ae18888 100644 --- a/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs +++ b/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs @@ -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) {