Ejemplo n.º 1
0
        public virtual ActionResult CreateABunch()
        {
            //farmers
            List<Farmer> farmers = new List<Farmer>();
            foreach (string farmerName in new string[] { "John", "Mark", "Sally", "June", "Susan" })
            {
                var repository = MvcApplication.container.Resolve<IFarmerRepository>();
                var farmer = new Farmer { Name = farmerName };
                repository.Save(farmer);
                farmers.Add(farmer);
            }

            //features
            List<Feature> features = new List<Feature>();
            foreach (String featureName in new string[] { "Hybrid", "Drought Resistant", "Pseudocereal", "Cereal" })
            {
                var repository = MvcApplication.container.Resolve<IFeatureRepository>();
                var feature = new Feature{ Name = featureName};
                repository.Save(feature);
                features.Add(feature);
            }

            //grains
            foreach (string grainName in new string[] { "Barley", "Wheat", "Maize", "Millet", "Oats", "Rye", "Triticale" })
            {
                var repository = MvcApplication.container.Resolve<IGrainRepository>();
                repository.Save(new Grain { Name = grainName, Features = GetRandomFeatures(features) }, GetRandomFamerID(farmers));
            }
            return RedirectToAction("Index");
        }
Ejemplo n.º 2
0
 public void Save(Feature feature)
 {
     using (var transaction = _session.BeginTransaction())
     {
         _session.Save(feature);
         transaction.Commit();
     }
 }