public async Task UpdateEmployee(int id, CreateOrUpdateEmployeeRequest request) { if (request.Experience < 0 || request.Salary <= 0) { throw new ArgumentException(); } if (request.PositionId != 2) { var tr = await context.Trainers.Where(c => c.EmployeeId == id).ToListAsync(); if (tr.Count != 0) { var man = new TrainerManager(context); await man.DeleteTrainer(tr[0].TrainerId); } } var emp = await context.Employees.FindAsync(id); emp.Name = request.Name; emp.PositionId = request.PositionId; emp.Experience = request.Experience; emp.Salary = request.Salary; emp.GymId = request.GymId; await context.SaveChangesAsync(); }
public async Task DeleteEmployee(int id) { var tr = await context.Trainers.Where(c => c.EmployeeId == id).ToListAsync(); var man = new TrainerManager(context); if (tr.Count != 0) { await man.DeleteTrainer(tr[0].TrainerId); } context.Employees.Remove(context.Employees.Find(id)); await context.SaveChangesAsync(); }
public static void MenouHeadMaster(int hm_id) { using (MyContext db = new MyContext()) { Console.WriteLine($"\nHello {db.HeadMasters.Find(hm_id).FirstName},\n"); while (1 == 1) { try { Console.WriteLine(""); Console.WriteLine("1 - Add a Student"); Console.WriteLine("2 - Update a Student"); Console.WriteLine("3 - Delete a Student"); Console.WriteLine("4 - Add a Trainer"); Console.WriteLine("5 - Update a Trainer"); Console.WriteLine("6 - Delete a Trainer"); Console.WriteLine("7 - Add a Course"); Console.WriteLine("8 - Update a Course"); Console.WriteLine("9 - Delete a Course"); Console.WriteLine("10 - Add an Assignment"); Console.WriteLine("11 - Update an Assignment"); Console.WriteLine("12 - Delete an Assignment"); Console.WriteLine("13 - Add a Head-Master"); Console.WriteLine("14 - Delete a Head-Master"); Console.WriteLine("15 - Relate Courses and Students(students per courses)"); Console.WriteLine("16 - UN-Relate Courses and Students(students per courses)"); Console.WriteLine("17 - Relate Trainers and Courses(Trainers per courses)"); Console.WriteLine("18 - UN-Relate Trainers and Courses(Trainers per courses)"); Console.WriteLine("19 - Relate Assignments and Courses(Assignments per courses)"); Console.WriteLine("20 - UN-Relate Assignments and Courses(Assignments per courses)"); Console.WriteLine("21 - Relate Assignments and Students(Assignments per Students)"); Console.WriteLine("22 - UN-Relate Assignments and Students(Assignments per Students)"); Console.WriteLine("23 - Exit from the programme"); Console.WriteLine("Please select one of the options: "); int user_chioce = Convert.ToInt32(Console.ReadLine()); switch (user_chioce) { case 1: StudentsManager.AddStudent(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 2: StudentsManager.UpdateStudent(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 3: StudentsManager.DeleteStudent(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 4: TrainerManager.AddTrainer(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 5: TrainerManager.UpdateTrainer(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 6: TrainerManager.DeleteTrainer(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 7: CourseManager.AddCourse(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 8: CourseManager.UpdateCourse(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 9: CourseManager.DeleteCourse(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 10: AssignmentManager.AddAssignment(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 11: AssignmentManager.UpdateAssignment(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 12: AssignmentManager.DeleteAssignment(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 13: HeadMasterManager.AddHeadMaster(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 14: HeadMasterManager.DeleteHeadMaster(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 15: StudentsManager.RelateStudentsCourses(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 16: StudentsManager.UNRelateStudentsCourses(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 17: TrainerManager.RelateCoursesToTrainers(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 18: TrainerManager.UNRelateCoursesToTrainers(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 19: CourseManager.RelateAssignmentsToCourses(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 20: CourseManager.UNRelateAssignmentsToCourses(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 21: StudentsManager.RelateStudentsAssignments(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 22: StudentsManager.UNRelateStudentsAssignments(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; case 23: Environment.Exit(0); break; } } catch (Exception) { Console.WriteLine("Wrong input"); } } } }