public void DeleteEmployee(Employee employee) { if ((employee.EntityState == EntityState.Detached)) this.ObjectContext.Employees.Attach(employee); employee.Employer = null; employee.LinkedUserAccount = null; employee.EmployeeHistoryEntries.Load(); employee.EmployeeHistoryEntries.ToArray(); foreach (var employeeHistoryEntry in employee.EmployeeHistoryEntries.ToArray()) this.DeleteEmployeeHistoryEntry(employeeHistoryEntry); employee.Routes.Load(); employee.Routes.Clear(); this.ObjectContext.Employees.DeleteObject(employee); }
public void UpdateEmployee(Employee currentEmployee) { currentEmployee.LastModified = DateTime.UtcNow; currentEmployee.LastModifyingUserId = CurrentUserAccount().Id; this.ObjectContext.Employees.AttachAsModified(currentEmployee); }
public void InsertEmployee(Employee employee) { if ((employee.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(employee, EntityState.Added); } else { this.ObjectContext.Employees.AddObject(employee); } }
/// <summary> /// Setup the employee link for a user account. /// If the employeeId is null or Empty, it will create a new Employee. /// Otherwise it will link the existing employee /// </summary> /// <param name="employeeId">The employee Id to link</param> /// <param name="userAccount">The user account</param> /// <param name="businessAccount">The business account</param> /// <param name="currentUserAccountId">For tracking</param> private void SetupEmployee(Guid? employeeId, Core.Models.CoreEntities.UserAccount userAccount, BusinessAccount businessAccount, Guid currentUserAccountId) { //clear any linked employees for this business account foreach (var oldEmployee in userAccount.LinkedEmployees.Where(e => e.EmployerId == businessAccount.Id).ToArray()) oldEmployee.LinkedUserAccountId = null; if (!employeeId.HasValue || employeeId.Value == Guid.Empty) //do not link the employee return; Employee employee; //add a new employee if (employeeId.Value == EntityTools.NewEntityId) { employee = new Employee { FirstName = userAccount.FirstName, LastName = userAccount.LastName, EmployerId = businessAccount.Id, CreatedDate = DateTime.UtcNow }; } //find the existing employee else { employee = CoreEntitiesContainer.Employees.First(e => e.Id == employeeId.Value); } //TODO CR Make extension method on ITrackable to do this employee.LastModified = DateTime.UtcNow; employee.LinkedUserAccountId = currentUserAccountId; employee.LinkedUserAccount = userAccount; }
/// <summary> /// Deprecated Method for adding a new object to the Employees EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEmployees(Employee employee) { base.AddObject("Employees", employee); }
/// <summary> /// Create a new Employee object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="employerId">Initial value of the EmployerId property.</param> /// <param name="createdDate">Initial value of the CreatedDate property.</param> public static Employee CreateEmployee(global::System.Guid id, global::System.Guid employerId, global::System.DateTime createdDate) { Employee employee = new Employee(); employee.Id = id; employee.EmployerId = employerId; employee.CreatedDate = createdDate; return employee; }