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


C# Infrastructure.Entry方法代码示例

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


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

示例1: 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

示例2: 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


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