当前位置: 首页>>代码示例>>C#>>正文


C# Infrastructure.SaveChanges方法代码示例

本文整理汇总了C#中Infrastructure.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Infrastructure.SaveChanges方法的具体用法?C# Infrastructure.SaveChanges怎么用?C# Infrastructure.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Infrastructure的用法示例。


在下文中一共展示了Infrastructure.SaveChanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Import

        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;
            }
        }
开发者ID:LCPS,项目名称:LCPS-NwUsers,代码行数:42,代码来源:LdapAccountImportRecord.cs

示例2: Import

        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();
            }
        }
开发者ID:LCPS,项目名称:LCPS-NwUsers,代码行数:96,代码来源:HRStaffImportRecord.cs

示例3: Seed

        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();
        }
开发者ID:APriceDev,项目名称:BlueEconomics,代码行数:61,代码来源:DBSeed.cs


注:本文中的Infrastructure.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。