Пример #1
0
        private void UpdatePositionHistory(Employee dbEmployee, Position newPosition)
        {
            var dbCurrentPosition = dbEmployee.PositionHistory.Single(ph => !ph.EndDate.HasValue);
            var now = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified);

            dbCurrentPosition.EndDate = now;
            var newPositionHistoryEntry = new EmployeePositionHistory {
                StartDate = now, Position = newPosition
            };

            dbEmployee.PositionHistory.Add(newPositionHistoryEntry);
        }
Пример #2
0
        public Task AddNewEmployee(Employee employee)
        {
            _dbContext.Add(employee);
            _dbContext.SetEntityState(employee.Position, State.Unchanged);

            var now = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified);
            var newPositionHistoryEntry = new EmployeePositionHistory {
                StartDate = now, Position = employee.Position
            };

            employee.PositionHistory.Add(newPositionHistoryEntry);

            return(_dbContext.SaveChangesAsync());
        }