public async Task <IActionResult> ConfirmAccount(FinancialAccountModel financialAccount) { var team = await _context.Teams.SingleOrDefaultAsync(m => m.Slug == TeamSlug && m.IsActive); if (team == null) { return(NotFound()); } financialAccount.Chart = financialAccount.Chart.SafeToUpper(); financialAccount.Account = financialAccount.Account.SafeToUpper(); financialAccount.SubAccount = financialAccount.SubAccount.SafeToUpper(); financialAccount.Project = financialAccount.Project.SafeToUpper(); if (!await _financialService.IsAccountValid(financialAccount.Chart, financialAccount.Account, financialAccount.SubAccount)) { ModelState.AddModelError("Account", "Valid Account Not Found."); } if (!string.IsNullOrWhiteSpace(financialAccount.Project) && !await _financialService.IsProjectValid(financialAccount.Project)) { ModelState.AddModelError("Project", "Project Not Valid."); } var accountLookup = new KfsAccount(); if (ModelState.IsValid) { accountLookup = await _financialService.GetAccount(financialAccount.Chart, financialAccount.Account); if (!accountLookup.IsValidIncomeAccount) { ModelState.AddModelError("Account", "Not An Income Account."); } } if (ModelState.IsValid) { //OK, it is valid, so lookup display values financialAccount.KfsAccount = accountLookup; if (!string.IsNullOrWhiteSpace(financialAccount.Project)) { financialAccount.KfsAccount.ProjectName = await _financialService.GetProjectName(financialAccount.Project); } if (!string.IsNullOrWhiteSpace(financialAccount.SubAccount)) { financialAccount.KfsAccount.SubAccountName = await _financialService.GetSubAccountName(financialAccount.Chart, financialAccount.Account, financialAccount.SubAccount); } financialAccount.Team = team; return(View(financialAccount)); } financialAccount.Team = team; return(View("CreateAccount", financialAccount)); }
public IActionResult Save([FromBody] FinancialAccountModel model) { //server side validations add in ModelState .AddModelError([field], [message]) if (ModelState.IsValid) { //var obj = model.ToEntity(); //_service.SaveVendor(obj); //model = obj.ToModel(); return(Ok(model)); } return(new BadRequestObjectResult(ModelState)); }
/// <summary> /// GET: FinancialAccounts/Create /// </summary> /// <returns></returns> public async Task <IActionResult> CreateAccount() { var team = await _context.Teams.SingleOrDefaultAsync(m => m.Slug == TeamSlug && m.IsActive); if (team == null) { return(NotFound()); } var model = new FinancialAccountModel { Team = team }; return(View(model)); }
public async Task <IActionResult> CreateAccount(FinancialAccountModel financialAccountModel, bool confirm) { var team = await _context.Teams.SingleOrDefaultAsync(m => m.Slug == TeamSlug && m.IsActive); if (team == null) { return(NotFound()); } var financialAccount = new FinancialAccount { Name = financialAccountModel.Name, Description = financialAccountModel.Description, Chart = financialAccountModel.Chart, Account = financialAccountModel.Account, SubAccount = financialAccountModel.SubAccount, Project = financialAccountModel.Project, IsDefault = financialAccountModel.IsDefault, TeamId = team.Id }; financialAccount.Chart = financialAccount.Chart.SafeToUpper(); financialAccount.Account = financialAccount.Account.SafeToUpper(); financialAccount.SubAccount = financialAccount.SubAccount.SafeToUpper(); financialAccount.Project = financialAccount.Project.SafeToUpper(); if (!await _financialService.IsAccountValid(financialAccount.Chart, financialAccount.Account, financialAccount.SubAccount)) { ModelState.AddModelError("Account", "Valid Account Not Found."); } if (!string.IsNullOrWhiteSpace(financialAccount.Project) && !await _financialService.IsProjectValid(financialAccount.Project)) { ModelState.AddModelError("Project", "Project Not Valid."); } if (ModelState.IsValid) { var accountLookup = await _financialService.GetAccount(financialAccount.Chart, financialAccount.Account); if (!accountLookup.IsValidIncomeAccount) { ModelState.AddModelError("Account", "Not An Income Account."); } } if (!confirm) { financialAccountModel.Team = team; return(View("CreateAccount", financialAccountModel)); } if (ModelState.IsValid) { if (financialAccount.IsDefault) { var accountToUpdate = await _context.FinancialAccounts.SingleOrDefaultAsync(a => a.TeamId == financialAccount.TeamId && a.IsDefault && a.IsActive); if (accountToUpdate != null) { accountToUpdate.IsDefault = false; _context.FinancialAccounts.Update(accountToUpdate); } } else { if (!await _context.FinancialAccounts.AnyAsync(a => (a.TeamId == financialAccount.TeamId && a.IsDefault && a.IsActive))) { financialAccount.IsDefault = true; } } _context.Add(financialAccount); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "FinancialAccounts", new { id = financialAccount.TeamId })); } financialAccount.Team = team; return(View(financialAccountModel)); }