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;
            }
        }
        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();
            }
        }
Exemple #3
0
        public static HRStaffPosition Load(string staffId, string buildingId, string employeeTypeId, string jobTitleId, LcpsDbContext db)
        {
            try
            {
                HRStaff  _staff = db.StaffMembers.FirstOrDefault(x => x.StaffId == staffId);

                HRBuilding _building = db.Buildings.FirstOrDefault(x => x.BuildingId == buildingId);

                HREmployeeType _employeeType = db.EmployeeTypes.FirstOrDefault(x => x.EmployeeTypeId == employeeTypeId);

                HRJobTitle _jobTitle = db.JobTitles.FirstOrDefault(x => x.JobTitleId == jobTitleId);

                if (_staff == null)
                    throw new Exception(string.Format("{0} is an invalid staff Id", staffId));

                if (_building == null)
                    throw new Exception(string.Format("{0} is an invalid building Id", buildingId));

                if (_employeeType == null)
                    throw new Exception(String.Format("{0} is an invalid employee type Id", employeeTypeId));

                if (_jobTitle == null)
                    throw new Exception(string.Format("{0} is an invalid job title Id", jobTitleId));

                HRStaffPosition p = new HRStaffPosition(_staff, _building, _employeeType, _jobTitle);

                return p;

            }
            catch (Exception ex)
            {
                throw new Exception("Could not load position", ex);
            }
        }