コード例 #1
0
ファイル: FundController.cs プロジェクト: thangma/thangmaapp
 public ActionResult Create(Fund fund)
 {
     try
     {
         if (ModelState.IsValid)
         {
             //fundRepository.InsertFund(fund);
             NHibernateHelper helper = new NHibernateHelper("thangma");
             // Notice the unit of work we are using is to commit
             //    one truck's data at a time.
             UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory);
             Repository<Fund> repository = new Repository<Fund>(unitOfWork.Session);
             //Truck truck = CreateFund();
             repository.Add(fund);
             unitOfWork.Commit();
             return RedirectToAction("Index");
         }
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return View(fund);
 }
コード例 #2
0
ファイル: FundController.cs プロジェクト: thangma/thangmaapp
 //public FundController(IFundRepository fundRepository)
 //{
 //    //this._fundRepository = fundRepository;
 //}//
 // GET: /Fund/
 public ActionResult Index(string returnUrl)
 {
     //var persons = fundRepository.GetFunds();
     //return View(persons);
     //fundRepository.InsertFund(fund);
     NHibernateHelper helper = new NHibernateHelper("thangma");
     // Notice the unit of work we are using is to commit
     //    one truck's data at a time.
     UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory);
     Repository<Fund> repository = new Repository<Fund>(unitOfWork.Session);
     var funds = repository.All();
     //Truck truck = CreateFund();
     return View(funds);
 }