Exemplo n.º 1
0
        public virtual async Task RemoveAsync(long id, CancellationToken ct = default)
        {
            var entity = await FindByIdAsync(id, ct);

            if (entity == null)
            {
                throw new NotFoundException();
            }

            _context.Remove(entity);
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        //https://exceptionnotfound.net/ef-core-inmemory-asp-net-core-store-database/
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new LavanderiaContext(
                       serviceProvider.GetRequiredService <DbContextOptions <LavanderiaContext> >()))
            {
                // Look for any board games.
                if (context.Usuarios.Any())
                {
                    return;   // Data was already seeded
                }

                context.Usuarios.AddRange(
                    new Usuario
                {
                    Id    = 1,
                    Login = "******",
                    Senha = "Hasbro",
                },
                    new Usuario
                {
                    Id    = 2,
                    Login = "******",
                    Senha = "Hasbro",
                },
                    new Usuario
                {
                    Id    = 3,
                    Login = "******",
                    Senha = "Days of Wonder",
                },
                    new Usuario
                {
                    Id    = 4,
                    Login = "******",
                    Senha = "Catan Studio",
                },
                    new Usuario
                {
                    Id    = 5,
                    Login = "******",
                    Senha = "Z-Man Games",
                },
                    new Usuario
                {
                    Id    = 6,
                    Login = "******",
                    Senha = "Jax Games",
                });

                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public bool Commit()
 {
     return(_context.SaveChanges() > 0);
 }