public async Task <IActionResult> GenerateAccountsGuide(int id) { if (await _currencyRepository.CountAsync() == 0) { return(BadRequest("you should to set default currency before.")); } if (await _accountRepository.CountAsync() > 0) { return(BadRequest("you already created accounts guide")); } var accounts = _predefinedGuideService.GetGuideAccounts(id); foreach (var accountModel in accounts) { var finalAccountId = accountModel.FinalAccountId == Guid.Empty ? null : accountModel.FinalAccountId; var parentAccountId = accountModel.ParentId == Guid.Empty ? null : accountModel.ParentId; var account = new Account(accountModel.GetName(_language), accountModel.Code, parentAccountId, finalAccountId, (AccountType)accountModel.Type, AccountDirectionType.Both, _defaultKeysOptions.Value.CurrencyId); account.Id = accountModel.Id; _accountRepository.Add(account, false); } var affectedRows = await _accountRepository.SaveAllAsync(); if (affectedRows > 0) { return(Ok()); } return(BadRequest()); }