Beispiel #1
0
        public ClientsDesignData(BusinessAccount serviceProvider, RegionsDesignData regionsDesignData)
        {
            var availableServiceTemplates = serviceProvider.ServiceTemplates.Where(st => st.ServiceTemplateLevel == ServiceTemplateLevel.ServiceProviderDefined).ToArray();

            InitializeClients();

            int clientIndex = 0;

            foreach (var client in DesignClients)
            {
                client.BusinessAccount = serviceProvider;

                //Add all Service Templates as AvailableServiceTemplates
                foreach (var availableServiceTemplate in availableServiceTemplates)
                {
                    var clientServiceTemplate = availableServiceTemplate.MakeChild(ServiceTemplateLevel.ClientDefined);
                    clientServiceTemplate.OwnerClient = client;
                }

                //Add Locations to the Client. Must do this before setting up the RecurringServices (they require locations)
                //This adds 2 locations per client. NOTE: If there are more than 24 clients, this or LocationsDesignData must be updated to have enough locations
                new LocationsDesignData(client, regionsDesignData.DesignRegions, clientIndex, 1);

                //Set the default billing location
                client.Locations.First().IsDefaultBillingLocation = true;

                //Add RecurringServices
                new RecurringServicesDesignData(client);

                clientIndex++;
            }
        }
        /// <summary>
        /// Clear and create the database. Then populate it with design data.
        /// </summary>
        public static void ClearCreateCoreEntitiesDatabaseAndPopulateDesignData()
        {
            ClearCreateCoreEntitiesDatabase();

            var container = new CoreEntitiesContainer(ServerConstants.ContainerConnectionString);

            //Setup blocks
            PopulateBlocks(container);

            //Setup Business Accounts (and ServiceTemplates)
            var businessAccountsDesignData = new BusinessAccountsDesignData();

            //Setup User Accounts
            var userAccountsDesignData = new UserAccountsDesignData
                                             {
                                                 //Set Passwords
                                                 Andrew = { PasswordHash = EncryptionTools.Hash("f00sballchamp", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 Jon = { PasswordHash = EncryptionTools.Hash("seltzer", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 Oren = { PasswordHash = EncryptionTools.Hash("nachoman", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 Zach = { PasswordHash = EncryptionTools.Hash("curlyhair", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 David = { PasswordHash = EncryptionTools.Hash("starofdavid", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 Linda = { PasswordHash = EncryptionTools.Hash("auntie", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 Terri = { PasswordHash = EncryptionTools.Hash("iam1randompassword", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" },
                                                 AlanMcClure = { PasswordHash = EncryptionTools.Hash("youngster", new byte[] { 65, 0, 65 }), TimeZone = "Eastern Standard Time" }
                                             };

            //Setup roles
            new RolesDesignData(businessAccountsDesignData, userAccountsDesignData);

            //var changes = container.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(o => o.Entity).OfType<ServiceTemplate>().Where(st => st.CreatedDate < DateTime.UtcNow.AddDays(-1) || st.LastModified < DateTime.UtcNow.AddDays(-1));

            //container.SaveChanges();

            //Populate ServiceProvider Design Data
            foreach (var serviceProvider in businessAccountsDesignData.DesignServiceProviders)
            {
                var employeesDesignData = new EmployeesDesignData(serviceProvider);
                foreach (var employee in employeesDesignData.DesignEmployees)
                    serviceProvider.Employees.Add(employee);

                //container.SaveChanges();

                //Add Vehicles (and Vehicle Maintenance, and VehicleTypes)
                var vehiclesDesignData = new VehiclesDesignData(serviceProvider);
                foreach (var vehicle in vehiclesDesignData.DesignVehicles)
                    serviceProvider.Vehicles.Add(vehicle);

                //container.SaveChanges();

                //Add Regions
                var regionsDesignData = new RegionsDesignData();
                foreach (var region in regionsDesignData.DesignRegions)
                    serviceProvider.Regions.Add(region);

                //container.SaveChanges();

                //Add Clients (and ContactInfo, Locations, and RecurringServices)
                var clientsDesignData = new ClientsDesignData(serviceProvider, regionsDesignData);
                foreach (var client in clientsDesignData.DesignClients)
                    serviceProvider.Clients.Add(client);

                //container.SaveChanges();

                //Add Routes (with RouteTasks, Vehicles, Technicians)
                var routesDesignData = new RoutesDesignData(serviceProvider, clientsDesignData, vehiclesDesignData, employeesDesignData);
                foreach (var route in routesDesignData.DesignRoutes)
                    serviceProvider.Routes.Add(route);

                //container.SaveChanges();

                //Add Services
                var servicesDesignData = new ServicesDesignData(serviceProvider, clientsDesignData.DesignClients.ElementAt(0), serviceProvider.ServiceTemplates);
                foreach (var service in servicesDesignData.DesignServices)
                    serviceProvider.ServicesToProvide.Add(service);

                //container.SaveChanges();
            }

            container.SaveChanges();
        }