public void Import(Infrastructure.LcpsDbContext context)
        {
            try
            {
                if (this.CrudStatus == ImportCrudStatus.InsertMember)
                {
                    LdapAccount ac = new LdapAccount()
                    {
                        AccountId = Guid.NewGuid(),
                        UserKey = _userKey,
                        UserName = this.UserName,
                        InitialPassword = this.Password,
                        Active = this.Active
                    };

                    context.LdapAccounts.Add(ac);
                }
                else
                {
                    LdapAccount ac = context.LdapAccounts
                    .FirstOrDefault(
                        x => x.UserKey.Equals(_userKey)
                        & x.UserName.ToLower() == this.UserName.ToLower()
                    );
                    ac.UserName = this.UserName;
                    ac.Active = this.Active;
                    context.Entry(ac).State = System.Data.Entity.EntityState.Modified;
                }

                context.SaveChanges();

                ImportReport = "Success";
                ImportStatus = ImportRecordStatus.success;

            }
            catch(Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ImportReport = ec.ToLineBreakString();
                ImportStatus = ImportRecordStatus.danger;
            }
        }
        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 void Seed(Infrastructure.BlueDbContext context)
        {
            context.Industries.AddOrUpdate(new Industry() { Code = 11, Name = "Management Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 13, Name = "Business and Financial Operations Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 15, Name = "Computer and Mathematical Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 17, Name = "Architecture and Engineering Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 19, Name = "Life, Physical, and Social Science Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 21, Name = "Community and Social Service Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 23, Name = "Legal Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 25, Name = "Education, Training, and Library Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 27, Name = "Arts, Design, Entertainment, Sports, and Media Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 29, Name = "Healthcare Practitioners and Technical Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 31, Name = "Healthcare Support Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 33, Name = "Protective Service Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 35, Name = "Food Preparation and Serving Related Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 37, Name = "Building and Grounds Cleaning and Maintenance Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 39, Name = "Personal Care and Service Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 41, Name = "Sales and Related Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 43, Name = "Office and Administrative Support Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 45, Name = "Farming, Fishing, and Forestry Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 47, Name = "Construction and Extraction Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 49, Name = "Installation, Maintenance, and Repair Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 51, Name = "Production Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 53, Name = "Transportation and Material Moving Occupations" });
            context.Industries.AddOrUpdate(new Industry() { Code = 55, Name = "Military Specific Occupations" });

            context.SaveChanges();

            //Education Score

            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Less than high school", Score = 4, Alias = "Lessthanhighschool" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "High school", Score = 3, Alias = "Highschooldiplomaorequivalent" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Some college, no degree", Score = 2, Alias = "Somecollegenodegree" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Associate's degree", Score = 1, Alias = "Associatesdegree" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Bachelor's degree", Score = 0, Alias = "Bachelorsdegree" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Master's degree", Score = 0, Alias = "Mastersdegree" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Doctoral or professional degree", Score = 0, Alias = "Doctoralorprofessionaldegree" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Post Secondary, Non Degree Award", Score = 0, Alias = "Postsecondarynondegreeaward" });
            context.EducationLevels.AddOrUpdate(new EducationLevel() { Name = "Typical level of education that most workers need to enter this occupation.", Score = 0, Alias = "Typical level of education that most workers need to enter this occupation." });

            context.SaveChanges();

            //LevelType
            context.LevelTypes.AddOrUpdate(new LevelType() { Name = "Premium", Alias = "" });
            context.LevelTypes.AddOrUpdate(new LevelType() { Name = "Great", Alias = "" });
            context.LevelTypes.AddOrUpdate(new LevelType() { Name = "Good", Alias = "" });
            context.LevelTypes.AddOrUpdate(new LevelType() { Name = "Not Recommended", Alias = "" });

            context.SaveChanges();

            context.WorkExperiences.AddOrUpdate(new WorkExperience() { Name = "1 to 5 Years", Alias = "1to5years" });
            context.WorkExperiences.AddOrUpdate(new WorkExperience() { Name = "Less than 1 Year", Alias = "Lessthan1year" });
            context.WorkExperiences.AddOrUpdate(new WorkExperience() { Name = "More than 5 Years", Alias = "Morethan5years" });
            context.WorkExperiences.AddOrUpdate(new WorkExperience() {
                Name = "Work experience that is commonly considered necessary by employers, or is a commonly accepted substitute for more formal types of training or education",
                Alias = "Work experience that is commonly considered necessary by employers, or is a commonly accepted substitute for more formal types of training or education." });

            context.WorkExperiences.AddOrUpdate(new WorkExperience() { Name = "None", Alias = "None" });

            context.SaveChanges();
        }