Exemplo n.º 1
0
 /// <summary>
 /// Create a new District object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static District CreateDistrict(global::System.Int32 id)
 {
     District district = new District();
     district.Id = id;
     return district;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Districts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDistricts(District district)
 {
     base.AddObject("Districts", district);
 }
Exemplo n.º 3
0
        public static bool SaveConfiguration(ConfigurationData data)
        {
            using (var ctx = new CityContainer())
            {
                var configurationExists = ctx.Configurations.Any(c => c.Name == data.ConfigurationName);
                if (configurationExists) return false;

                var poiTypes = ctx.PoiTypes.Where(t => data.PoiTypes.Contains(t.Code));

                var newConfiguration = new Configuration
                                           {
                                               Name = data.ConfigurationName,
                                               SelectionMethod = ctx.SelectionMethods.Single(m => m.Name == data.SimulationMethodName),
                                               SimulationStartDate = data.SimulationStartDate,
                                               SimulationEndDate = data.SimulationEndDate,
                                               PersonDemandsPerDay = data.DemandsPerPersonPerDay,
                                               CreditCardBalanceMin = data.CreditCardBalanceMin,
                                               CreditCardBalanceMax = data.CreditCardBalanceMax,
                                               CreditCardLimitMin = data.CreditCardLimitMin,
                                               CreditCardLimitMax = data.CreditCardLimitMax,
                                               TransactionValueMin = data.TransactionValueMin,
                                               TransactionValueMax = data.TransactionValueMax
                                           };

                // Assign POI circle areas
                foreach (var circleAreaObject in data.CircleAreas)
                {
                    newConfiguration.CircleAreas.Add(new CircleArea
                                                         {
                                                             Configuration = newConfiguration,
                                                             Lat = circleAreaObject.Pushpin.Location.Latitude,
                                                             Lng = circleAreaObject.Pushpin.Location.Longitude,
                                                             Range = circleAreaObject.Range
                                                         });
                }

                // Assign POI types for configuration
                foreach (var poiType in poiTypes)
                    newConfiguration.PoiTypes.Add(poiType);

                // Assign Districts for configuration
                foreach (var polygon in data.Polygons)
                {
                    var district = new District
                                       {
                                           Configuration = newConfiguration,
                                           Population = polygon.Population,
                                           Name = polygon.DistrictName
                                       };

                    foreach (var location in polygon.Locations)
                    {
                        district.MapPoints.Add(new MapPoint
                                                   {
                                                       Lat = location.Latitude,
                                                       Lng = location.Longitude
                                                   });
                    }
                }

                ctx.Configurations.AddObject(newConfiguration);
                ctx.SaveChanges();

                return true;
            }
        }