Пример #1
0
        public async Task <Client> AddClientAsync(Client client)
        {
            await _lcpContext.Clients.AddAsync(client);

            var result = await _lcpContext.SaveChangesAsync();

            if (result != 0)
            {
                return(client);
            }

            return(null);
        }
Пример #2
0
        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);
            }
        }