public IActionResult AddAccount(int customerId, [FromBody] AccountCreateDto accountCreateDto) { Customer customer = NGContext.Customers.Include(c => c.Accounts).FirstOrDefault(c => c.Id == customerId); if (customer == null) { return(NotFound()); } if (accountCreateDto == null) { return(BadRequest()); } Account account = AutoMapper.Mapper.Map <Account>(accountCreateDto); account.CustomerId = customerId; NGContext.Accounts.Add(account); NGContext.SaveChanges(); return(GetCustomer(customerId)); }
public static void RestSeed(this NGContext context) { //delete tables context.AccountTypes.RemoveRange(context.AccountTypes); context.ClassCodes.RemoveRange(context.ClassCodes); context.Currencies.RemoveRange(context.Currencies); context.Customers.RemoveRange(context.Customers); context.Accounts.RemoveRange(context.Accounts); context.SaveChanges(); //generate data IEnumerable <AccountType> AccountTypes = CreateAccountTypes(); context.AccountTypes.AddRange(AccountTypes); context.SaveChanges(); IEnumerable <ClassCode> ClassCodes = CreateClassCodes(AccountTypes); context.ClassCodes.AddRange(ClassCodes); context.SaveChanges(); IEnumerable <Currency> Currencies = CreateCurrencies(); context.Currencies.AddRange(Currencies); context.SaveChanges(); IEnumerable <Customer> Customers = CreateCustomers(); context.Customers.AddRange(Customers); context.SaveChanges(); IEnumerable <Account> Accounts = CreateAccounts(Customers, AccountTypes.ToArray(), ClassCodes.ToArray(), Currencies.ToArray()); context.Accounts.AddRange(Accounts); context.SaveChanges(); }