/// <summary>
        /// Adds a district to the system, only if it does not exist.
        /// </summary>
        private static void AddInitialDistrict(this IDbAppContext context, District initialDistrict)
        {
            District district = context.GetDistrictByMinistryDistrictId(initialDistrict.MinistryDistrictID);

            if (district != null)
            {
                return;
            }

            district = new District
            {
                MinistryDistrictID = initialDistrict.MinistryDistrictID,
                Name      = initialDistrict.Name,
                StartDate = initialDistrict.StartDate
            };

            if (initialDistrict.Region != null)
            {
                Region region = context.GetRegionByMinistryRegionId(initialDistrict.Region.MinistryRegionID);
                district.Region = region;
            }
            else
            {
                district.Region = null;
            }

            context.Districts.Add(district);
            context.SaveChanges();
        }
        private static void AddInitialServiceArea(this IDbAppContext context, ServiceArea initialServiceArea)
        {
            ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(initialServiceArea.MinistryServiceAreaID);

            if (serviceArea != null)
            {
                return;
            }

            serviceArea = new ServiceArea
            {
                MinistryServiceAreaID = initialServiceArea.MinistryServiceAreaID,
                Name      = initialServiceArea.Name,
                StartDate = initialServiceArea.StartDate
            };

            if (initialServiceArea.District != null)
            {
                District district = context.GetDistrictByMinistryDistrictId(initialServiceArea.District.MinistryDistrictID);
                serviceArea.District = district;
            }
            else
            {
                serviceArea.District = null;
            }

            context.ServiceAreas.Add(serviceArea);
            context.SaveChanges();
        }
Exemplo n.º 3
0
        private static void AddInitialServiceArea(this IDbAppContext context, ServiceArea initialServiceArea)
        {
            ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(initialServiceArea.MinistryServiceAreaID);

            if (serviceArea != null)
            {
                return;
            }

            serviceArea = new ServiceArea
            {
                MinistryServiceAreaID = initialServiceArea.MinistryServiceAreaID,
                Name                   = initialServiceArea.Name,
                StartDate              = initialServiceArea.StartDate,
                AppCreateUserid        = SystemId,
                AppCreateTimestamp     = DateTime.UtcNow,
                AppLastUpdateUserid    = SystemId,
                AppLastUpdateTimestamp = DateTime.UtcNow
            };

            if (initialServiceArea.District != null)
            {
                District district = context.GetDistrictByMinistryDistrictId(initialServiceArea.District.MinistryDistrictID);
                serviceArea.District = district;
            }
            else
            {
                serviceArea.District = null;
            }

            context.ServiceAreas.Add(serviceArea);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a district to the system, only if it does not exist.
        /// </summary>
        private static void AddInitialDistrict(this IDbAppContext context, District initialDistrict)
        {
            District district = context.GetDistrictByMinistryDistrictId(initialDistrict.MinistryDistrictID);

            if (district != null)
            {
                return;
            }

            district = new District
            {
                MinistryDistrictID = initialDistrict.MinistryDistrictID,
                Name                   = initialDistrict.Name,
                StartDate              = initialDistrict.StartDate,
                AppCreateUserid        = SystemId,
                AppCreateTimestamp     = DateTime.UtcNow,
                AppLastUpdateUserid    = SystemId,
                AppLastUpdateTimestamp = DateTime.UtcNow
            };

            if (initialDistrict.Region != null)
            {
                Region region = context.GetRegionByMinistryRegionId(initialDistrict.Region.MinistryRegionID);
                district.Region = region;
            }
            else
            {
                district.Region = null;
            }

            context.Districts.Add(district);
        }
        /// <summary>
        /// Adds a user to the system, only if they do not exist.
        /// </summary>
        private static void AddInitialUser(this IDbAppContext context, User initialUser)
        {
            User user = context.GetUserBySmUserId(initialUser.SmUserId);

            if (user != null)
            {
                return;
            }

            user           = new User();
            user.Active    = true;
            user.Email     = initialUser.Email;
            user.GivenName = initialUser.GivenName;
            user.Initials  = initialUser.Initials;
            user.SmAuthorizationDirectory = initialUser.SmAuthorizationDirectory;
            user.SmUserId = initialUser.SmUserId;
            user.Surname  = initialUser.Surname;

            District district = null;

            if (initialUser.District != null)
            {
                district = context.GetDistrictByMinistryDistrictId(initialUser.District.MinistryDistrictID);
            }

            user.District = district;

            context.Users.Add(user);
            context.SaveChanges();

            string[] userRoles = initialUser.UserRoles.Select(x => x.Role.Name).ToArray();
            if (user.UserRoles == null)
            {
                user.UserRoles = new List <UserRole>();
            }

            foreach (string userRole in userRoles)
            {
                Role role = context.GetRole(userRole);
                if (role != null)
                {
                    user.UserRoles.Add(
                        new UserRole
                    {
                        EffectiveDate = DateTime.UtcNow.Date,
                        Role          = role
                    });
                }
            }

            context.Users.Update(user);
            context.SaveChanges();
        }
        private static void AddInitialUser(this IDbAppContext context, User initialUser)
        {
            User user = context.GetUserBySmUserId(initialUser.SmUserId);

            if (user != null)
            {
                return;
            }

            user = new User
            {
                Active    = true,
                Email     = initialUser.Email,
                GivenName = initialUser.GivenName,
                Initials  = initialUser.Initials,
                SmAuthorizationDirectory = initialUser.SmAuthorizationDirectory,
                SmUserId = initialUser.SmUserId,
                Surname  = initialUser.Surname
            };


            District district = null;

            if (initialUser.District != null)
            {
                district = context.GetDistrictByMinistryDistrictId(initialUser.District.MinistryDistrictID);
            }

            user.District = district;

            context.Users.Add(user);
            context.SaveChanges();

            string[] userRoles = initialUser.UserRoles.Select(x => x.Role.Name).ToArray();

            if (user.UserRoles == null)
            {
                user.UserRoles = new List <UserRole>();
            }

            foreach (string userRole in userRoles)
            {
                Role role = context.GetRole(userRole);
                if (role != null)
                {
                    user.UserRoles.Add(
                        new UserRole
                    {
                        EffectiveDate = DateTime.UtcNow,
                        Role          = role
                    });
                }
            }

            string[] userGroups = initialUser.GroupMemberships.Select(x => x.Group.Name).ToArray();
            if (user.GroupMemberships == null)
            {
                user.GroupMemberships = new List <GroupMembership>();
            }

            foreach (string userGroup in userGroups)
            {
                Group group = context.GetGroup(userGroup);
                if (group != null)
                {
                    user.GroupMemberships.Add(
                        new GroupMembership
                    {
                        Active = true,
                        Group  = context.GetGroup("Other")
                    });
                }
            }

            context.Users.Update(user);
            context.SaveChanges();
        }
Exemplo n.º 7
0
        private static void AddInitialUser(this IDbAppContext context, User initialUser)
        {
            User user = context.GetUserBySmUserId(initialUser.SmUserId);

            if (user != null)
            {
                return;
            }

            user = new User
            {
                Active    = true,
                Email     = initialUser.Email,
                GivenName = initialUser.GivenName,
                Initials  = initialUser.Initials,
                SmAuthorizationDirectory = initialUser.SmAuthorizationDirectory,
                SmUserId               = initialUser.SmUserId,
                Surname                = initialUser.Surname,
                AppCreateUserid        = SystemId,
                AppCreateTimestamp     = DateTime.UtcNow,
                AppLastUpdateUserid    = SystemId,
                AppLastUpdateTimestamp = DateTime.UtcNow
            };

            District district = null;

            if (initialUser.District != null)
            {
                district = context.GetDistrictByMinistryDistrictId(initialUser.District.MinistryDistrictID);
            }

            user.District = district;

            string[] userRoles = initialUser.UserRoles.Select(x => x.Role.Name).ToArray();

            if (user.UserRoles == null)
            {
                user.UserRoles = new List <UserRole>();
            }

            foreach (string userRole in userRoles)
            {
                Role role = context.GetRole(userRole);

                if (role != null)
                {
                    user.UserRoles.Add(
                        new UserRole
                    {
                        EffectiveDate          = DateTime.UtcNow,
                        Role                   = role,
                        AppCreateUserid        = SystemId,
                        AppCreateTimestamp     = DateTime.UtcNow,
                        AppLastUpdateUserid    = SystemId,
                        AppLastUpdateTimestamp = DateTime.UtcNow
                    });
                }
            }

            context.Users.Add(user);
        }