public async Task <Client> AddClientAsync(Client client) { await _lcpContext.Clients.AddAsync(client); var result = await _lcpContext.SaveChangesAsync(); if (result != 0) { return(client); } return(null); }
public static async Task SeedAsync(LcpContext lcpContext, ILoggerFactory loggerFactory) { try { // Any checks for any records if (!lcpContext.Clients.Any()) { var clientsData = File.ReadAllText("../LCP.Infrastructure/SeedData/clients.json"); var clients = JsonSerializer.Deserialize <List <Client> >(clientsData); foreach (var client in clients) { lcpContext.Clients.Add(client); } await lcpContext.SaveChangesAsync(); } } catch (Exception ex) { var logger = loggerFactory.CreateLogger <LcpContextSeed>(); logger.LogError(ex.Message); } }