/// <summary> /// Function to add new employee to the database, and creating its attendance document /// </summary> /// <param name="attendanceCollectionLink"></param> /// <param name="employeeColelctionLink"></param> /// <returns></returns> public async Task GetNewEmployeeAsync(string attendanceCollectionLink, string employeeColelctionLink) { // Getting the Employee details Employee employee = GetEmployeeDetails(); if (employee != null) { // Calling OnNewEmployeeAdd event NewEmployeeAdditionTrigger.EmployeeCreatorHandler -= new NewEmployeeAdditionTrigger.EmployeeCreator(CreateNewEmployeeAsync); NewEmployeeAdditionTrigger.EmployeeCreatorHandler += new NewEmployeeAdditionTrigger.EmployeeCreator(CreateNewEmployeeAsync); await NewEmployeeAdditionTrigger.OnAddNewEmployeeAsync(employee, employeeColelctionLink, attendanceCollectionLink); // Write to Log await db.CreateandWriteLogAsync(Properties.Resources.LogNewEmployeeAdded + employee.id); } }
/// <summary> /// Inserts the new employee to the database and triggers post insertion events. /// </summary> /// <param name="employee">The new employee object</param> /// <param name="employeeColelctionLink">The link to employee collection</param> /// <param name="attendanceCollectionLink">The link to attendance collection</param> /// <returns></returns> public async Task CreateNewEmployeeAsync(Employee employee, string employeeColelctionLink, string attendanceCollectionLink) { bool result = await db.InsertNewEmployeeAsync(employee, employeeColelctionLink); if (result is true) { // call OnNewEmployeeAdded event NewEmployeeAdditionTrigger.AttendanceCreatorHandler -= new NewEmployeeAdditionTrigger.AttendanceCreator(CreateNewAttendanceDocForEmployeeAsync); NewEmployeeAdditionTrigger.AttendanceCreatorHandler += new NewEmployeeAdditionTrigger.AttendanceCreator(CreateNewAttendanceDocForEmployeeAsync); await NewEmployeeAdditionTrigger.OnNewEmployeeAddedAsync(employee.id, attendanceCollectionLink); // Write to Log await db.CreateandWriteLogAsync(Properties.Resources.LogNewAttendanceCreated + employee.id); } else { Console.WriteLine(Properties.Resources.TryAgain); } }