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


C# oikonomosEntities.AddToPeople方法代码示例

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


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

示例1: CreateNewChurch

        public static void CreateNewChurch(Person currentPerson, ChurchSettingsViewModel churchSettings)
        {
            if (currentPerson.HasPermission(common.Permissions.SystemAdministrator))
            {
                using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    var newChurch = new Church();
                    context.AddToChurches(newChurch);
                    newChurch.Created = DateTime.Now;

                    PopulateChurchModel(churchSettings, newChurch);
                    newChurch.EmailLogin = "[email protected]";
                    newChurch.EmailPassword = "sandton2000";
                    PopulateChurchAddress(churchSettings, context, newChurch);
                    context.SaveChanges();

                    //Save Roles
                    var currentChurchRoles = context.Roles.Where(r => (r.ChurchId == currentPerson.ChurchId && r.Name != "System Administrator")).ToList();
                    foreach (var currentRole in currentChurchRoles)
                    {
                        var newChurchRole = new Role();
                        context.AddToRoles(newChurchRole);
                        newChurchRole.Created = DateTime.Now;
                        newChurchRole.Changed = DateTime.Now;
                        newChurchRole.Name = currentRole.Name;
                        newChurchRole.DisplayName = currentRole.DisplayName;
                        newChurchRole.ChurchId = newChurch.ChurchId;

                        foreach (var permission in currentRole.PermissionRoles)
                        {
                            var newRolePerm = new PermissionRole();
                            context.AddToPermissionRoles(newRolePerm);
                            newRolePerm.Created = DateTime.Now;
                            newRolePerm.Changed = DateTime.Now;
                            newRolePerm.PermissionId = permission.PermissionId;
                            newChurchRole.PermissionRoles.Add(newRolePerm);
                        }
                    }

                    context.SaveChanges();

                    //Update Role that can be set by any role
                    foreach (var currentRole in currentChurchRoles)
                    {
                        var newRole = context.Roles.Where(r => (r.ChurchId == newChurch.ChurchId && r.Name == currentRole.Name)).FirstOrDefault();
                        foreach (var roleToSet in currentRole.CanSetRoles)
                        {
                            if (roleToSet.Name != "System Administrator")
                            {
                                var newRoleToSet = context.Roles.FirstOrDefault(r => (r.ChurchId == newChurch.ChurchId && r.Name == roleToSet.Name));
                                newRole.CanSetRoles.Add(newRoleToSet);
                            }
                        }
                    }

                    context.SaveChanges();

                    var churchAdministrator              = new Person();
                    context.AddToPeople(churchAdministrator);
                    churchAdministrator.Created          = DateTime.Now;
                    churchAdministrator.Changed          = DateTime.Now;
                    churchAdministrator.Firstname        = churchSettings.ContactFirstname;
                    churchAdministrator.Church           = newChurch;
                    var churchAdministratorFamily        = new Family();
                    context.AddToFamilies(churchAdministratorFamily);
                    churchAdministratorFamily.FamilyName = churchSettings.ContactSurname;
                    churchAdministratorFamily.Created    = DateTime.Now;
                    churchAdministratorFamily.Changed    = DateTime.Now;
                    churchAdministrator.Family           = churchAdministratorFamily;

                    context.SaveChanges();

                    //Set the new persons role to administrator
                    churchAdministrator.RoleId = context.Roles.First(r => (r.ChurchId == newChurch.ChurchId && r.Name == "Church Administrator")).RoleId;
                    context.SaveChanges();

                    //Update Church Optional Fields
                    var churchOptionalFields = context.ChurchOptionalFields.Where(c=>c.ChurchId == currentPerson.ChurchId);
                    foreach (var co in churchOptionalFields)
                    {
                        var newCo = new ChurchOptionalField();
                        context.AddToChurchOptionalFields(newCo);
                        newCo.Created = DateTime.Now;
                        newCo.Changed = DateTime.Now;
                        newCo.ChurchId = newChurch.ChurchId;
                        newCo.OptionalFieldId = co.OptionalFieldId;
                        newCo.Visible = co.Visible;
                    }

                    context.SaveChanges();
                }
            }
        }
开发者ID:rodown,项目名称:funwithoiky,代码行数:93,代码来源:SettingsDataAccessor.cs

示例2: GetPersonToSaveEntity

        private static void GetPersonToSaveEntity(PersonViewModel person, Person currentPerson, oikonomosEntities context, out bool sendWelcomeEmail, out Church church, out Person personToSave)
        {
            sendWelcomeEmail = false;

            //We need some settings from the Church table
            church = (from c in context.Churches
                      where c.ChurchId == currentPerson.ChurchId
                      select c).FirstOrDefault();

            personToSave = new Person();
            if (person.PersonId != 0)
            {
                personToSave = FetchPerson(person.PersonId, context, currentPerson);
            }
            else
            {
                context.AddToPeople(personToSave);
                personToSave.ChurchId = church.ChurchId;
                personToSave.Church = church;

                personToSave.Created = DateTime.Now;
                if (church.SendWelcome)
                {
                    sendWelcomeEmail = true;
                }

                if (person.GroupId > 0)
                {
                    var pg = new PersonGroup
                                 {
                                     GroupId = person.GroupId,
                                     Person  = personToSave,
                                     Joined  = DateTime.Now,
                                     Created = DateTime.Now,
                                     Changed = DateTime.Now
                                 };
                    personToSave.PersonGroups.Add(pg);
                }
            }

            if (person.FamilyId == 0)
            {
                if (person.FindFamily)
                {
                    var family = (from f in context.Families
                                  join p in context.People
                                      on f.FamilyId equals p.FamilyId
                                  join g in context.PersonGroups
                                      on p.PersonId equals g.PersonId
                                  where f.FamilyName == person.Surname
                                      && g.GroupId == person.GroupId
                                  select f).FirstOrDefault();
                    if (family == null)
                    {
                        personToSave.Family = new Family();
                        personToSave.Family.Created = DateTime.Now;
                    }
                    else
                    {
                        personToSave.Family = family;
                    }
                }
                else
                {
                    personToSave.Family = new Family();
                    personToSave.Family.Created = DateTime.Now;
                }
            }
            else
            {
                personToSave.Family = (from f in context.Families
                                       where f.FamilyId == person.FamilyId
                                       select f).FirstOrDefault();

                if (personToSave.Family == null)
                {
                    personToSave.Family = new Family();
                    personToSave.Family.Created = DateTime.Now;
                }
            }

            personToSave.Firstname = person.Firstname;
            personToSave.Family.FamilyName = person.Surname;
            personToSave.Email = person.Email;
            personToSave.DateOfBirth = person.DateOfBirth_Value;
        }
开发者ID:rodown,项目名称:funwithoiky,代码行数:86,代码来源:PersonDataAccessor.cs

示例3: CreateNewChurch

        public static void CreateNewChurch(Person currentPerson, ChurchSettingsViewModel churchSettings)
        {
            if (!currentPerson.HasPermission(Permissions.SystemAdministrator)) return;
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var newChurch = new Church();
                context.AddToChurches(newChurch);
                newChurch.Created = DateTime.Now;

                PopulateChurchModel(churchSettings, newChurch);
                newChurch.EmailLogin = "[email protected]";
                newChurch.EmailPassword = "sandton2000";
                newChurch.Country = "South Africa";
                PopulateChurchAddress(churchSettings, context, newChurch);
                context.SaveChanges();

                //Save Roles
                var currentChurchRoles = context.Roles.Where(r => (r.ChurchId == currentPerson.ChurchId && r.Name != "System Administrator")).ToList();
                foreach (var currentRole in currentChurchRoles)
                {
                    var newChurchRole = new Role();
                    context.AddToRoles(newChurchRole);
                    newChurchRole.Created = DateTime.Now;
                    newChurchRole.Changed = DateTime.Now;
                    newChurchRole.Name = currentRole.Name;
                    newChurchRole.DisplayName = currentRole.DisplayName;
                    newChurchRole.ChurchId = newChurch.ChurchId;

                    foreach (var permission in currentRole.PermissionRoles)
                    {
                        var newRolePerm = new PermissionRole();
                        context.AddToPermissionRoles(newRolePerm);
                        newRolePerm.Created = DateTime.Now;
                        newRolePerm.Changed = DateTime.Now;
                        newRolePerm.PermissionId = permission.PermissionId;
                        newChurchRole.PermissionRoles.Add(newRolePerm);
                    }
                }

                context.SaveChanges();

                //Update Role that can be set by any role
                foreach (var currentRole in currentChurchRoles)
                {
                    var newRole = context.Roles.FirstOrDefault(r => (r.ChurchId == newChurch.ChurchId && r.Name == currentRole.Name));
                    foreach (var newRoleToSet in from roleToSet in currentRole.CanSetRoles where roleToSet.Name != "System Administrator" select context.Roles.FirstOrDefault(r => (r.ChurchId == newChurch.ChurchId && r.Name == roleToSet.Name)))
                    {
                        newRole.CanSetRoles.Add(newRoleToSet);
                    }
                }

                context.SaveChanges();

                var personAddress = new Address {Created = DateTime.Now, Changed = DateTime.Now, Line1 = string.Empty, Line2=string.Empty, Line3=string.Empty, Line4 = string.Empty};
                context.AddToAddresses(personAddress);

                var churchAdministrator              = new Person();
                context.AddToPeople(churchAdministrator);
                churchAdministrator.Created          = DateTime.Now;
                churchAdministrator.Changed          = DateTime.Now;
                churchAdministrator.Firstname        = churchSettings.ContactFirstname;
                churchAdministrator.Church           = newChurch;
                churchAdministrator.Email            = churchSettings.OfficeEmail;
                var churchAdministratorFamily        = new Family();
                context.AddToFamilies(churchAdministratorFamily);
                churchAdministratorFamily.FamilyName = churchSettings.ContactSurname;
                churchAdministratorFamily.Created    = DateTime.Now;
                churchAdministratorFamily.Changed    = DateTime.Now;
                churchAdministrator.Family           = churchAdministratorFamily;
                churchAdministrator.Family.Address   = personAddress;

                context.SaveChanges();

                //Set the new persons role to administrator
                var personChurchRecord = new PersonChurch
                    {
                        Person = churchAdministrator,
                        Church = newChurch,
                        Role = context.Roles.First(r => (r.ChurchId == newChurch.ChurchId && r.Name == "Church Administrator"))
                    };

                context.AddToPersonChurches(personChurchRecord);
                context.SaveChanges();

                //Update Church Optional Fields
                var churchOptionalFields = context.ChurchOptionalFields.Where(c=>c.ChurchId == currentPerson.ChurchId);
                foreach (var co in churchOptionalFields)
                {
                    var newCo = new ChurchOptionalField();
                    context.AddToChurchOptionalFields(newCo);
                    newCo.Created = DateTime.Now;
                    newCo.Changed = DateTime.Now;
                    newCo.ChurchId = newChurch.ChurchId;
                    newCo.OptionalFieldId = co.OptionalFieldId;
                    newCo.Visible = co.Visible;
                }

                context.SaveChanges();
            }
        }
开发者ID:petermunnings,项目名称:funwithoiky,代码行数:100,代码来源:SettingsDataAccessor.cs


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