public async Task <T> AddAsync(T entity)
        {
            _context.Set <T>().Add(entity);
            await _context.SaveChangesAsync();

            return(entity);
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id_Tienda,Nombre,Encargado,Contacto,Direccion")] Tiendas tiendas)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tiendas);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tiendas));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id_Producto,Nombre,Precio,Cantidad,Fecha_Vencimiento,Id_Categoria")] Productos productos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productos));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id_Categoria,Nombre")] Categorias categorias)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categorias);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categorias));
        }
예제 #5
0
    public async Task <bool> DeleteAsync(Guid id)
    {
        var data = await _db.FindAsync(id);

        if (data == null)
        {
            return(false);
        }
        _db.Remove(data);
        return(await _context.SaveChangesAsync() > 0);
    }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id_Venta,Codigo_Factura,Nombre_Cliente,Fecha,Total,Id_Tienda")] Ventas ventas)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ventas);
                await _context.SaveChangesAsync();

                return(RedirectToAction("CreateDetalleVenta", new { id = ventas.Id_Venta }));
            }
            return(View(ventas));
        }
예제 #7
0
        public async Task <IActionResult> Create(Professor professor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(professor);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(professor));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("Nome,Valor,Id")] Procedimento procedimento)
        {
            if (ModelState.IsValid)
            {
                procedimento.Id = Guid.NewGuid();
                _context.Add(procedimento);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(procedimento));
        }
예제 #9
0
        public async Task <IActionResult> Create(Curso curso)
        {
            if (ModelState.IsValid)
            {
                curso.Id = Guid.NewGuid();
                _context.Add(curso);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProfessorId"] = new SelectList(_context.Set <Professor>(), "Id", "Nome", curso.ProfessorId);
            return(View(curso));
        }
예제 #10
0
    public async Task SaveTweetsAsync(List <ThirdNews> list)
    {
        var result = new List <ThirdNews>(list);
        var news   = await _context.ThirdNews.OrderByDescending(n => n.DatePublished)
                     .Where(n => n.Type == NewsSource.Tweet)
                     .Take(50).ToListAsync();

        foreach (var item in list)
        {
            if (news.Any(n => n.IdentityId == item.IdentityId ||
                         n.Title.GetSimilar(item.Title) >= 0.6))
            {
                result.Remove(item);
            }
        }

        if (result.Count > 0)
        {
            await _context.AddRangeAsync(result);

            await _context.SaveChangesAsync();

            _logger.LogInformation("===Start=== Add tweets " + result.Count);
        }
    }
예제 #11
0
        public async Task Add(T Object)
        {
            using ContextBase data = new ContextBase(_OptionBuilder);
            _ = await data.Set <T>().AddAsync(Object);

            _ = await data.SaveChangesAsync();
        }
예제 #12
0
        public async Task <bool> ConfirmaCompraCarrinhoUsuario(string userId)
        {
            try
            {
                using (var banco = new ContextBase(_optionsbuilder))
                {
                    var compraUsuario = new CompraUsuario();
                    compraUsuario.ListaProdutos = new List <Produto>();

                    var produtosCarrinhoUsuario = await(from p in banco.Produto
                                                        join c in banco.CompraUsuario on p.Id equals c.IdProduto
                                                        where c.UserId.Equals(userId) && c.Estado == EnumEstadoCompra.Produto_Carrinho
                                                        select c).AsNoTracking().ToListAsync();

                    produtosCarrinhoUsuario.ForEach(p =>
                    {
                        p.Estado = EnumEstadoCompra.Produto_Comprado;
                    });

                    banco.UpdateRange(produtosCarrinhoUsuario);
                    await banco.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception erro)
            {
                return(false);
            }
        }
예제 #13
0
    public async Task AddThirdNewsAsync(List <ThirdNews> list)
    {
        var result = new List <ThirdNews>(list);
        var news   = await _context.ThirdNews.OrderByDescending(n => n.DatePublished)
                     .Where(n => n.Type == NewsSource.News)
                     .Take(50).ToListAsync();

        _logger.LogInformation("today total news: " + list.Count);

        foreach (var item in list)
        {
            if (news.Any(n => n.Title.GetSimilar(item.Title) >= 0.6 || n.Title.Equals(item.Title)))
            {
                result.Remove(item);
            }
        }
        _logger.LogInformation("added news: " + result.Count);

        if (result.Count > 0)
        {
            await _context.AddRangeAsync(result);

            await _context.SaveChangesAsync();
        }
    }
        public async Task SaveChangesAsync_UpdateAdress_ShouldSetModifiedByProperty()
        {
            //Arrange - Add Address and Update the Address
            Address address = new Address
            {
                Street     = "Test Address",
                Number     = "1",
                PostalCode = "28303",
                State      = "Bremen",
                Country    = "Germany"
            };

            ContextBase.Addresses.Add(address);

            await ContextBase.SaveChangesAsync();

            address.Street = "Example";

            //Act
            await ContextBase.SaveChangesAsync();

            //Assert
            Assert.True(address.ModifiedBy == "00000000-0000-0000-0000-000000000000");
            Assert.True(address.ModifiedBy != null);
        }
예제 #15
0
 public async Task Excluir(T Objeto)
 {
     using (var dados = new ContextBase(_OptionsBuilder))
     {
         dados.Set <T>().Remove(Objeto);
         await dados.SaveChangesAsync();
     }
 }
예제 #16
0
 public async Task Atualizar(T Objeto)
 {
     using (var dados = new ContextBase(_OptionsBuilder))
     {
         dados.Set <T>().Update(Objeto);
         await dados.SaveChangesAsync();
     }
 }
예제 #17
0
 public async Task Update(T obj)
 {
     using (var data = new ContextBase(_optionsBuilder))
     {
         data.Set <T>().Update(obj);
         await data.SaveChangesAsync();
     }
 }
예제 #18
0
 public async Task <int> UpdateAsync(T Entity)
 {
     using (var database = new ContextBase(this._OptionsBuilder.Options))
     {
         database.Set <T>().Update(Entity);
         return(await database.SaveChangesAsync());
     }
 }
예제 #19
0
 public async Task Delete(T Objeto)
 {
     using (var data = new ContextBase(_optionsBuilder))
     {
         data.Set <T>().Remove(Objeto);
         await data.SaveChangesAsync();
     }
 }
 public async Task Update(T Objeto)
 {
     using (var data = new ContextBase(_OptionsBuild))
     {
         data.Set <T>().Update(Objeto);
         await data.SaveChangesAsync();
     }
 }
예제 #21
0
        public async Task Adicionar(T Objeto)
        {
            using (var dados = new ContextBase(_OptionsBuilder))
            {
                await dados.Set <T>().AddAsync(Objeto);

                await dados.SaveChangesAsync();
            }
        }
예제 #22
0
        public async Task Add(T Objeto)
        {
            using (var data = new ContextBase(_optionsBuilder))
            {
                await data.Set <T>().AddAsync(Objeto);

                await data.SaveChangesAsync();
            }
        }
예제 #23
0
 public async Task <bool> Commit()
 {
     try
     {
         return((await _context.SaveChangesAsync()) > 0);
     }
     catch (Exception ex)
     {
         _notify.AddNotification(new NotificationMessage("Ocorreu um erro ao processar a operação."));
         return(false);
     }
 }
예제 #24
0
        public async Task AtualizarTipoUsuario(string userID, TipoUsuario tipoUsuario)
        {
            using (var banco = new ContextBase(_optionsbuilder))
            {
                var usuario = await banco.ApplicationUser.FirstOrDefaultAsync(u => u.Id.Equals(userID));

                if (usuario != null)
                {
                    usuario.Tipo = tipoUsuario;
                    banco.ApplicationUser.Update(usuario);
                    await banco.SaveChangesAsync();
                }
            }
        }
예제 #25
0
        public async Task <bool> Inserir(ContaCorrenteLancamentos contaCorrenteLancamento)
        {
            using (var data = new ContextBase(_OptionsBuilder))
            {
                var contacorrente = await Task.Run(() => data.ContaCorrente.Include(c => c.Agencia).Where(cc => cc.Id == contaCorrenteLancamento.ContaCorrente.Id).FirstOrDefaultAsync());

                contaCorrenteLancamento.ContaCorrente = contacorrente;
                await data.ContaCorrenteLancamentos.AddAsync(contaCorrenteLancamento);

                int id = await data.SaveChangesAsync();

                return(id > 0);
            }
        }
        public async Task SaveChangesAsync_GivenNewAddress_ShouldSetCreatedOnProperty()
        {
            //Arrange - Add Address
            Address address = new Address
            {
                Street     = "Test Address",
                Number     = "1",
                PostalCode = "28303",
                State      = "Bremen",
                Country    = "Germany"
            };

            ContextBase.Addresses.Add(address);

            //Act
            await ContextBase.SaveChangesAsync();

            //Assert
            Assert.True(address.CreatedOn != null);
        }
        public async Task SaveChangesAsync_UpdateAddress_RowVersionNewerThanCreatedOn()
        {
            //Arrange - Add Address and Update the Address
            Address address = new Address
            {
                Street     = "Test Address",
                Number     = "1",
                PostalCode = "28303",
                State      = "Bremen",
                Country    = "Germany"
            };

            ContextBase.Addresses.Add(address);

            await ContextBase.SaveChangesAsync();

            address.Street = "Example";

            //Act
            await ContextBase.SaveChangesAsync();

            //Assert
            Assert.True(address.RowVersion > address.CreatedOn);
        }
예제 #28
0
 public async Task <int> SaveChanges()
 {
     return(await Db.SaveChangesAsync());
 }
예제 #29
0
 public async Task <int> SaveChanges()
 {
     return(await _contextBase.SaveChangesAsync());
 }
예제 #30
0
 public async Task Delete(T Object)
 {
     using ContextBase data = new ContextBase(_OptionBuilder);
     _ = data.Set <T>().Remove(Object);
     _ = await data.SaveChangesAsync();
 }