Exemple #1
0
        public HRStaffRecord(HRStaff staff, HRStaffPosition position, HRBuilding building, HREmployeeType employeeType, HRJobTitle jobTitle)
        {
            if (staff != null)
            {
                FirstName = staff.FirstName;
                MiddleInitial = staff.MiddleInitial;
                LastName = staff.LastName;
                Gender = staff.Gender;
                Birthdate = staff.Birthdate;
                StaffKey = staff.StaffKey;
                StaffId = staff.StaffId;
            }

            if (position != null)
            {

                PositionKey = position.PositionKey;
                StaffKey = position.StaffMemberId;
                BuildingKey = position.BuildingKey;
                EmployeeTypeKey = position.EmployeeTypeKey;
                JobTitleKey = position.JobTitleKey;
                Status = position.Status;
                FiscalYear = position.FiscalYear;
            }
        }
Exemple #2
0
 public HRStaffPosition(HRStaff staff, HRBuilding building, HREmployeeType employeeType, HRJobTitle jobTitle)
 {
     _staff = staff;
     _building = building;
     _employeeType = employeeType;
     _jobTitle = jobTitle;
     StaffMemberId = staff.StaffKey;
     BuildingKey = building.BuildingKey;
     EmployeeTypeKey = employeeType.EmployeeTypeLinkId;
     JobTitleKey = jobTitle.JobTitleKey;
 }
        public void Import(Infrastructure.LcpsDbContext context)
        {
            if (CrudStatus == ImportCrudStatus.None)
                return;

            Guid _staffKey = Guid.Empty;

            HRStaffPosition[] pp = context.StaffPositions.Where(x => x.StaffMemberId.Equals(_staffKey)).ToArray();
            if(pp.Count() > 0)
            {
                context.StaffPositions.RemoveRange(pp);
                context.SaveChanges();
            }

            try
            {

                if (CrudStatus.HasFlag(ImportCrudStatus.InsertMember))
                {
                    HRStaff staff = new HRStaff()
                    {
                        StaffKey = Guid.NewGuid(),
                        StaffId = this.StaffId,
                        Birthdate = this.Birthdate,
                        FirstName = this.FirstName,
                        MiddleInitial = this.MiddleInitial,
                        LastName = this.LastName,
                        Gender = this.Gender
                    };

                    _staffKey = staff.StaffKey;

                    context.StaffMembers.Add(staff);
                }

                if (CrudStatus.HasFlag(ImportCrudStatus.UpdateMember))
                {
                    HRStaff staff = context.StaffMembers.First(x => x.StaffId.ToLower() == this.StaffId.ToLower());
                    staff.Birthdate = this.Birthdate;
                    staff.FirstName = this.FirstName;
                    staff.MiddleInitial = this.MiddleInitial;
                    staff.LastName = this.LastName;
                    staff.Gender = this.Gender;

                    _staffKey = staff.StaffKey;

                    context.Entry(staff).State = System.Data.Entity.EntityState.Modified;
                }

                if (CrudStatus.HasFlag(ImportCrudStatus.CreateMembership))
                {
                    if (_staffKey.Equals(Guid.Empty))
                        _staffKey = context.StaffMembers.First(x => x.StaffId.ToLower() == this.StaffId.ToLower()).StaffKey;

                    HRStaffPosition p = new HRStaffPosition()
                    {
                        StaffMemberId = _staffKey,
                        PositionKey = Guid.NewGuid(),
                        BuildingKey = _staffDefinition.Building.BuildingKey,
                        EmployeeTypeKey = _staffDefinition.EmployeeType.EmployeeTypeLinkId,
                        JobTitleKey = _staffDefinition.JobTitle.JobTitleKey,
                        Status = this.Status,
                        FiscalYear = this.FiscalYear
                    };

                    context.StaffPositions.Add(p);
                }

                if (CrudStatus.HasFlag(ImportCrudStatus.UpdateMembership))
                {
                    if (_staffKey.Equals(Guid.Empty))
                        _staffKey = context.StaffMembers.First(x => x.StaffId.ToLower() == this.StaffId.ToLower()).StaffKey;

                    HRStaffPosition p = context.StaffPositions
                        .First(x => x.StaffMemberId.Equals(_staffKey)
                        & x.BuildingKey.Equals(_staffDefinition.Building.BuildingKey)
                        & x.EmployeeTypeKey.Equals(_staffDefinition.EmployeeType.EmployeeTypeLinkId)
                        & x.JobTitleKey.Equals(_staffDefinition.JobTitle.JobTitleKey));

                    p.Status = this.Status;
                    p.FiscalYear = this.FiscalYear;

                    context.Entry(p).State = System.Data.Entity.EntityState.Modified;
                }

                context.SaveChanges();

                ImportStatus = ImportRecordStatus.success;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ImportStatus = ImportRecordStatus.danger;
                ImportReport = ec.ToLineBreakString();
            }
        }
 public HRStaff ToStaff()
 {
     HRStaff b = new HRStaff();
     AnvilEntity e = new AnvilEntity(this);
     e.CopyTo(b);
     return b;
 }