public Employee(QmsEmployee employee) { this.EmplId = employee.EmplId; this.FirstName = employee.FirstName; this.MiddleName = employee.MiddleName; this.LastName = employee.LastName; this.EmailAddress = employee.EmailAddress; this.AgencySubElement = employee.AgencySubElement; this.PersonnelOfficeIdentifier = employee.PersonnelOfficeIdentifier; setPersonnelOfficeIdentifierDescription(employee.PersonnelOfficeIdentifier); this.DepartmentId = employee.DepartmentId; this.PayPlan = employee.PayPlan; this.Grade = employee.Grade; this.ManagerId = employee.ManagerId; }
void setEmployeesForDeletionOrUpdate() { foreach(QmsEmployee existingEmployee in existingEmployees) { QmsEmployee emp = newEmployees.Where(e => e.EmplId == existingEmployee.EmplId).SingleOrDefault(); if(emp!=null) { int updatedFieldCount = 0; if(existingEmployee.FirstName != emp.FirstName) { existingEmployee.FirstName = emp.FirstName; updatedFieldCount++; } if(existingEmployee.LastName != emp.LastName) { existingEmployee.LastName = emp.LastName; updatedFieldCount++; } if(existingEmployee.MiddleName != emp.MiddleName) { existingEmployee.MiddleName = emp.MiddleName; updatedFieldCount++; } if(existingEmployee.DepartmentId != emp.DepartmentId) { existingEmployee.DepartmentId = emp.DepartmentId; updatedFieldCount++; } if(existingEmployee.EmailAddress != emp.EmailAddress) { existingEmployee.EmailAddress = emp.EmailAddress; updatedFieldCount++; } if(existingEmployee.AgencySubElement != emp.AgencySubElement) { existingEmployee.AgencySubElement = emp.AgencySubElement; updatedFieldCount++; } if(existingEmployee.PersonnelOfficeIdentifier != emp.PersonnelOfficeIdentifier) { existingEmployee.PersonnelOfficeIdentifier = emp.PersonnelOfficeIdentifier; updatedFieldCount++; } if(existingEmployee.Grade != emp.Grade) { existingEmployee.Grade = emp.Grade; updatedFieldCount++; } if(existingEmployee.PayPlan != emp.PayPlan) { existingEmployee.PayPlan = emp.PayPlan; updatedFieldCount++; } if(existingEmployee.ManagerId != emp.ManagerId) { existingEmployee.ManagerId = emp.ManagerId; updatedFieldCount++; } if(existingEmployee.UserKey != emp.UserKey) { existingEmployee.UserKey = emp.UserKey; updatedFieldCount++; } if (updatedFieldCount > 0) { existingEmployee.UpdatedAt =DateTime.Now; RecordsToUpdate.Add(existingEmployee); Logger.Log.Record(string.Format("Employee {0} {1},{2} has {3} field(s) that were updated",existingEmployee.EmplId,existingEmployee.LastName,existingEmployee.FirstName,updatedFieldCount)); } } else //employee in database but not in csv file so we delete them { existingEmployee.DeletedAt = DateTime.Now; existingEmployee.UpdatedAt = DateTime.Now; RecordsToDelete.Add(existingEmployee); Logger.Log.Record(string.Format("Employee {0} {1},{2} to be deleted",existingEmployee.EmplId,existingEmployee.LastName,existingEmployee.FirstName)); } } Logger.Log.Record(RecordsToUpdate.Count + " records to be updated in the database."); Logger.Log.Record(RecordsToDelete.Count + " records to be deleted in the database."); }