public int Add(Categoria entity) { var entityEntry = db.Add(entity); db.SaveChanges(); return(entityEntry.Entity.IdCategoria); }
public int Add(CursoPostDto dto) { Curso entity = new Curso() { DataInicio = dto.DataInicio, DataTermino = dto.DataTermino, NumeroAlunos = dto.NumeroAlunos, Descricao = dto.Descricao, IdCategoria = dto.IdCategoria }; var entityEntry = db.Add(entity); db.SaveChanges(); return(entityEntry.Entity.IdCurso); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new EnsinoMemoryContext( serviceProvider.GetRequiredService <DbContextOptions <EnsinoMemoryContext> >())) { // Look for any board games. if (context.Categoria.Any()) { return; // Data was already seeded } List <Categoria> lista = new List <Categoria>(); lista.Add(new Categoria() { Descricao = "Comportamental", Codigo = 1 }); lista.Add(new Categoria() { Descricao = "Programação", Codigo = 2 }); lista.Add(new Categoria() { Descricao = "Qualidade", Codigo = 3 }); lista.Add(new Categoria() { Descricao = "Processos", Codigo = 4 }); context.Categoria.AddRange(lista); context.SaveChanges(); } }