public ActionResult Create(TellerManagement teller) { teller.userId = Convert.ToInt32(Request.Form["Users"]); teller.AccountManagementId = Convert.ToInt32(Request.Form["Account"]); teller.Date = DateTime.Now.ToString(); var user = new User(); var glAccount = new GlAccountManagement(); var id = Convert.ToInt32(teller.userId); var userInDb = _user.Get(id); var glAccountInDb = Accountcontext.Get(teller.AccountManagementId); //Updating userassigned userInDb.UserAssigned = true; _user.Update(user); //Updating AccountAssigned glAccountInDb.AccountAssigned = true; Accountcontext.Update(glAccount); //Adding into database TellerContext.Add(teller); //saving for teller TellerContext.Save(teller); return(RedirectToAction("Index", "TellerManagement")); //return View(viewmodel); }
public ActionResult Create(TellerManagement teller) { var userRepository = new Repository <User>(); ViewBag.UserName = userRepository.GetAll(); var glAccountRepository = new Repository <GLAccount>(); ViewBag.GLAccount = glAccountRepository.GetAll(); var glCategoryRepository = new Repository <GLCategory>(); ViewBag.GLtype = glCategoryRepository.GetAll(); try { using (ISession session = NHibernateHelper.Session) { using (ITransaction transaction = session.BeginTransaction()) { var user = session.Query <User>().FirstOrDefault(b => b.Id == teller.User.Id); teller.User = user; var till = session.Query <GLAccount>().FirstOrDefault(b => b.Id == teller.TillAccount.Id); teller.TillAccount = till; if (!IsCashAsset(till)) { ModelState.AddModelError("TillAccount", "Till Account must be a Cash Asset"); } till.IsAssigned = true; user.IsAssigned = true; teller.DateAdded = DateTime.Now; teller.DateUpdated = DateTime.Now; session.Save(teller); transaction.Commit(); } } return(RedirectToAction("Index")); } catch (Exception exception) { ViewBag.Exception = exception.Message; } //ViewBag.GLtype = Enum.GetValues(typeof(GLCategoryType)); return(View()); }