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 SaveSavingsConfig(SavingsAccountConfig config) { var glAccount = new GlAccount(); var configInDb = _context.GetSavingsConfig(); var glAccountInDb = _glAccountContext.Get(config.InterestExpenseGlId); if (config.Id == 0) //setup new configuration { glAccountInDb.IsAssigned = true; // Update the gl account to is assigned _glAccountContext.Update(glAccount); config.Status = true; _context.SaveSavings(config); TempData["Success"] = "Configurations Added Successfully"; return(RedirectToAction("SavingsAccount")); } if (config.Id != 0) //update current savings configuration { configInDb.CInterestRate = config.CInterestRate; configInDb.MinBalance = config.MinBalance; configInDb.InterestPayableGlId = config.InterestPayableGlId; if (config.InterestExpenseGlId == 0) //check if gl account is the same { configInDb.InterestExpenseGlId = configInDb.InterestExpenseGlId; } else { var newGlAccountInDb = _glAccountContext.Get(configInDb.InterestExpenseGlId); // free up the old gl account that was assigned newGlAccountInDb.IsAssigned = false; _glAccountContext.Update(glAccount); configInDb.InterestExpenseGlId = config.InterestExpenseGlId; glAccountInDb.IsAssigned = true; // Update the new gl account to is assigned _glAccountContext.Update(glAccount); } TempData["Success"] = "Configurations Updated Successfully"; _context.UpdateSavings(config); } return(RedirectToAction("SavingsAccount")); }