예제 #1
0
        public virtual ActionResult Create(Grain grain, int farmerID, string features)
        {
            try
            {
                var repo = MvcApplication.container.Resolve<IGrainRepository>();
                grain.Features.Clear();
                foreach (string feature in features.Split(','))
                {
                    grain.Features.Add(new Feature { Name = feature });
                }
                repo.Save(grain, farmerID);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
예제 #2
0
        public void Save(Grain grain, int farmerID)
        {
            using (var transaction = _session.BeginTransaction())
            {
                try
                {
                    grain.Farmer = _session.Load<Farmer>(farmerID);
                    _session.Merge(grain);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    if (transaction.IsActive)
                    {
                        transaction.Rollback();
                    }
                }

            }
        }