public ActionResult Save(GlAccount account) { if (ModelState.IsValid) { var accountInDb = _context.Get(account.Id); var glAccountNameIsUnique = _context.NameIsUnique(account.Name) || account.Id != 0 && accountInDb.Name == account.Name; //check if account Name is Unchanged for update and set is unique to true if (account.Id == 0 && glAccountNameIsUnique) //add account { if (Request.Form["tillAccount"] == "on") { account.IsTillAccount = true; } account.AccountCode = _context.GenerateGlAccountCode(account.GlCategoryId); _context.Save(account); TempData["Success"] = "GL Account Added Successfully"; return(RedirectToAction("Index")); } if (account.Id != 0 && glAccountNameIsUnique) //update account { accountInDb.Name = account.Name; accountInDb.BranchId = account.BranchId; _context.Update(account); TempData["Success"] = "Update Successful"; return(RedirectToAction("Index")); } if (!glAccountNameIsUnique) { ModelState.AddModelError("nameTaken", "This Name Exist"); } } var branches = _userContext.GetBranches(); var glCategories = _context.GetGlCategories(); var tAccount = new NewGlAccountViewModel() { Branches = branches, GlCategories = glCategories }; return(View("GlAccountForm", tAccount)); }
public ActionResult Save(Teller teller) { int userId = Convert.ToInt32(Request.Form["userId"]); if (_userContext.GetUnassigned(userId) != null) { var user = new User(); var glAccount = new GlAccount(); var userInDb = _userContext.Get(userId); var glAccountInDb = _glAccountContext.Get(teller.GlAccountId); userInDb.IsAssigned = true; _userContext.Update(user); glAccountInDb.IsAssigned = true; _glAccountContext.Update(glAccount); teller.UserId = userId; _context.Save(teller); TempData["Success"] = "Till Account Assigned Successfully"; return(RedirectToAction("Index")); } ViewBag.hasTillAccount = "User Has Till Account"; var tellers = _context.GetWithAll(); var selectedUser = _userContext.Get(userId); var selectedGlAccounts = _glAccountContext.GetAllUnassigned(); var selectedViewModel = new NewTellerViewModel { User = selectedUser, GlAccount = selectedGlAccounts }; return(View("TellerForm", selectedViewModel)); }
public ActionResult SavingsAccount() { var config = _context.GetSavingsConfig(); object glAccount = null; object interestPayableGl = null; if (config != null)//check if savings configurations exist { glAccount = _glAccountContext.Get(config.InterestExpenseGlId); interestPayableGl = _glAccountContext.Get(Convert.ToInt32(config.InterestPayableGlId)); } //for the dropdowns options var glAccounts = _glAccountContext.GetAllExpenseAccount(); var interestPayableGls = _glAccountContext.GetAllLiabilityAccount(); var viewModel = new SavingsAccountConfigViewModel(config) { InterestExpenseGl = (GlAccount)glAccount, InterestPayableGl = (GlAccount)interestPayableGl, InterestExpenseGls = glAccounts, InterestPayableGls = interestPayableGls }; return(View("SavingsAccountTypeForm", viewModel)); }