public IActionResult CompanyAccountCreate(int companyId) { List <EmployeeAccountViewModel> employeesAccounts = employeeService.GetEmployeesByCompanyId(companyId) .Select(e => new EmployeeAccountViewModel { Employee = e, EmployeeId = e.Id, Limits = selectListService.GetLimits(), }).ToList(); CompanyAccountCreateViewModel model = new CompanyAccountCreateViewModel { Currencies = selectListService.GetCurrencies(), CompanyId = companyId, EmployeeAccounts = employeesAccounts }; return(View(model)); }
public async Task <IActionResult> CompanyAccountCreate(CompanyAccountCreateViewModel model) { if (ModelState.IsValid) { Company company = await context.Companies.FirstOrDefaultAsync(c => c.Id == model.CompanyId); Currency currency = await context.Currencies.FirstOrDefaultAsync(c => c.Id == model.CurrencyId); Account account = accountService.CreateAccount(company, currency); accountService.AddAccount(account); foreach (var acc in model.EmployeeAccounts) { acc.Account = account; } companyService.AddRangeEmployeeAccounts(model.EmployeeAccounts); return(RedirectToAction("CompanyInfo", "Company", new { id = company.Id })); } foreach (EmployeeAccountViewModel limit in model.EmployeeAccounts) { limit.Limits = selectListService.GetLimits(); } model.Currencies = selectListService.GetCurrencies(); var limits = selectListService.GetLimits(); foreach (var employeeAccountViewModel in model.EmployeeAccounts) { employeeAccountViewModel.Employee = employeeService.FindEmployeeById(employeeAccountViewModel.EmployeeId.Value); employeeAccountViewModel.Limits = limits; } return(View(model)); }