-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataService.cs
More file actions
41 lines (31 loc) · 1 KB
/
DataService.cs
File metadata and controls
41 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using ControleEstoque.Models;
using controleEstoque.Repositories;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
namespace controleEstoque
{
class DataService : IDataService
{
private readonly ApplicationContext contexto;
private readonly IProdutoRepository produtoRepository;
public DataService(ApplicationContext contexto, IProdutoRepository produtoRepository)
{
this.contexto = contexto;
this.produtoRepository = produtoRepository;
}
public void InicializaBD()
{
contexto.Database.Migrate();
List<Livro> livros = GetLivros();
produtoRepository.SaveProdutos(livros);
}
private static List<Livro> GetLivros()
{
var json = File.ReadAllText("livros.json");
var livros = JsonConvert.DeserializeObject<List<Livro>>(json);
return livros;
}
}
}