public ActionResult AddAccount(AddAccountViewModel model) { Account account = new Account() { AccountCode = model.AccountCode, AccountName = model.AccountName, AccountClassId = model.AccountClass, ParentAccountId = model.ParentAccountId == -1 ? null : model.ParentAccountId, CompanyId = _administrationService.GetDefaultCompany().Id, }; _financialService.AddAccount(account); return RedirectToAction("Accounts"); }
public ActionResult AddAccount(AddAccountViewModel model) { Account account = new Account() { AccountCode = model.AccountCode, AccountName = model.AccountName, AccountClassId = model.AccountClass, ParentAccountId = model.ParentAccountId == -1 ? null : model.ParentAccountId, CreatedBy = User.Identity.Name, ModifiedBy = User.Identity.Name, CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now }; _financialService.AddAccount(account); return RedirectToAction("Accounts"); }
public void AddAccount(Account account) { if (account.IsContraAccount && account.ContraAccounts.Count > 0) throw new Exception("An account cannot have contra account if the account is already contra account."); if (GetAccounts().Any(a => a.AccountCode == account.AccountCode && a.Id != account.Id)) throw new Exception("Account code already exist."); if (account.ParentAccountId.HasValue) { var parent = GetAccount(account.ParentAccountId.Value); if (account.Id == parent.ParentAccountId) throw new Exception("Cyclic parent/child account."); } _accountRepo.Insert(account); }