예제 #1
0
        /// <summary>
        /// Deletes an employee from the database.
        /// </summary>
        /// <param name="employeeIn">The employee to delete from the db</param>
        public async static void DeleteEmployeeFromDB(Employee employeeIn)
        {
            //count number of database access attempts
            int AttemptCount = 0;

            do
            {
                try
                {
                    AttemptCount++;
                    using (EmpManEntities db = new EmpManEntities())
                    {
                        // find and remove employee from the db with the same ID as employeeIn
                        db.Employees.RemoveRange(db.Employees.Where(p => p.ID == employeeIn.ID));
                        // save changes to the database asynchronously for better responsiveness
                        await db.SaveChangesAsync();

                        //return here if successful
                        return;
                    }
                }
                catch (Exception ex)
                {
                    //log all errors that occur
                    LogFunctions.LogException(ex);
                }
            }while ((AttemptCount < MAX_NUMBER_OF_ATTEMPTS) || ConfirmContinue(AttemptCount));

            //give notice to exit application if user decides to not keep trying
            Application.Exit();
        }
예제 #2
0
        /// <summary>
        /// Adds a new employee to the database.
        /// </summary>
        /// <param name="employeeIn">The employee to add to the db</param>
        public async static void AddEmployeeToDB(Employee employeeIn)
        {
            //count number of database access attempts
            int AttemptCount = 0;

            do
            {
                try
                {
                    AttemptCount++;
                    using (EmpManEntities db = new EmpManEntities())
                    {
                        // add the employee to the db
                        db.Employees.Add(employeeIn);
                        // save changes to the database asynchronously for better responsiveness
                        await db.SaveChangesAsync();

                        //return here if successful
                        return;
                    }
                }
                catch (Exception ex)
                {
                    //log all errors that occur
                    LogFunctions.LogException(ex);
                }
            }while ((AttemptCount < MAX_NUMBER_OF_ATTEMPTS) || ConfirmContinue(AttemptCount));

            //give notice to exit application if user decides to not keep trying
            Application.Exit();
        }
예제 #3
0
        /// <summary>
        /// Saves Edits to a current employee in the database.
        /// </summary>
        /// <param name="employeeIn">An edited employee object</param>
        public async static void SaveEmployeeEditsToDB(Employee employeeIn)
        {
            //count number of database access attempts
            int AttemptCount = 0;

            do
            {
                try
                {
                    AttemptCount++;
                    using (EmpManEntities db = new EmpManEntities())
                    {
                        //find the employee in the db with the same ID as employeeIn
                        Employee EmployeeToEdit = db.Employees.Where(p => p.ID == employeeIn.ID).FirstOrDefault();
                        //set all db employee properties = employeeIn's properties
                        EmployeeToEdit.FirstName  = employeeIn.FirstName;
                        EmployeeToEdit.MiddleName = employeeIn.MiddleName;
                        EmployeeToEdit.LastName   = employeeIn.LastName;
                        EmployeeToEdit.Phone      = employeeIn.Phone;
                        EmployeeToEdit.JobTitle   = employeeIn.JobTitle;
                        EmployeeToEdit.Photo      = employeeIn.Photo;
                        EmployeeToEdit.Email      = employeeIn.Email;
                        EmployeeToEdit.FullName   = employeeIn.FullName;
                        // save changes to the database asynchronously for better responsiveness
                        await db.SaveChangesAsync();

                        //return here if successful
                        return;
                    }
                }
                catch (Exception ex)
                {
                    //log all errors that occur
                    LogFunctions.LogException(ex);
                }
            }while ((AttemptCount < MAX_NUMBER_OF_ATTEMPTS) || ConfirmContinue(AttemptCount));

            //give notice to exit application if user decides to not keep trying
            Application.Exit();
        }