예제 #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");
        }
예제 #2
0
 public virtual ActionResult Edit(Farmer farmer)
 {
     try
     {
         var repository = MvcApplication.container.Resolve<IFarmerRepository>();
         repository.Save(farmer);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
예제 #3
0
        public void Save(Farmer farmer)
        {
            using (var transaction = _session.BeginTransaction())
            {
                try
                {
                    _session.SaveOrUpdate(farmer);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    if (transaction.IsActive)
                    {
                        transaction.Rollback();
                    }
                }

            }
        }