public bool Emprestar() { if (Emprestimos.Count == 0) { for (int i = 0; i < 1; i++) { if (disponivel) { Emprestimos.Add(new Emprestimo(DateTime.Now, null)); return(true); } } } else { for (int i = 0; i < Emprestimos.Count; i++) { if (disponivel) { Emprestimos.Add(new Emprestimo(DateTime.Now, null)); return(true); } } } return(false); }
public async Task <IActionResult> Edit(int id, [Bind("IdEmprestimos,Emprestado,PrevisaoDevolucao,Devolucao")] Emprestimos emprestimos) { if (id != emprestimos.IdEmprestimos) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(emprestimos); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmprestimosExists(emprestimos.IdEmprestimos)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(emprestimos)); }
public void Editar(Emprestimos livro) { using (var db = new SeminarioVDbContext()) { db.Emprestimos.Update(livro); db.SaveChanges(); } }
public void Novo(Emprestimos livro) { using (var db = new SeminarioVDbContext()) { db.Emprestimos.Add(livro); db.SaveChanges(); } }
public async Task GetAll() { Emprestimos = await _dbContext.Emprestimos .Include(p => p.Cliente) .Include(p => p.Jogo) .ToListAsync(); SemEmprestimosCadastrados = !Emprestimos.Any(); }
public void Excluir(int id)//Deletar registro da base de dados através do id_user { Emprestimos pExcluir = BuscarPorId(id); if (pExcluir != null) { contexto.Emprestimos.Remove(pExcluir); contexto.SaveChanges(); } }
public void Novo(Emprestimos operacao) { var emprestimo = new EmprestimosRepository(); var livro = new LivrosRepository(); if (LivroDisponivel(operacao.IdLivro)) { operacao.DataPrevistaDevolucao = DateTime.Now.AddDays(7); operacao.DataRealDevolucao = null; operacao.DataRetirada = DateTime.Now; emprestimo.Novo(operacao); } }
private EmprestimoViewModel GetEmprestimoViewModelEdicao(Emprestimos emprestimo) { List <Livros> livros = this._dataService.GetLivros(); List <Usuarios> usuarios = this._dataService.GetUsuarios(); EmprestimoViewModel emprestimoViewModel = new EmprestimoViewModel(); emprestimoViewModel.Id = emprestimo.Id; emprestimoViewModel.LivroId = emprestimo.Livro.Id; emprestimoViewModel.UsuarioId = emprestimo.Usuario.Id; emprestimoViewModel.DataEmprestimo = emprestimo.DataEmprestimo; emprestimoViewModel.DataDevolucao = emprestimo.DataDevolucao; emprestimoViewModel.Devolvido = emprestimo.Devolvido; emprestimoViewModel.Livros = livros; emprestimoViewModel.Usuarios = usuarios; return(emprestimoViewModel); }
public async Task <IActionResult> Create([Bind("IdEmprestimos,Emprestado,PrevisaoDevolucao,Devolucao")] Emprestimos emprestimos) { if (ModelState.IsValid) { emprestimos.Livro = _context.Livros.First(x => x.IdLivro.Equals(emprestimos.Livro.IdLivro)); emprestimos.Cliente = _context.Clientes.First(x => x.IdCliente.Equals(emprestimos.Cliente.IdCliente)); _context.Add(emprestimos); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(emprestimos)); }
public IActionResult Cadastro(EmprestimoViewModel emprestimoViewModel) { if (ModelState.IsValid) { Livros livro = _dataService.GetLivro(emprestimoViewModel.LivroId); if (emprestimoViewModel.Devolvido) { this._dataService.AumentarQuantidadeLivro(emprestimoViewModel.LivroId); } else { if (livro.Quantidade < 1) { ViewBag.Error = "This book cannot be borrowred because it's out of stock."; EmprestimoViewModel viewModel = GetEmprestimoViewModelAdicao(); return(View(viewModel)); } else { this._dataService.DiminuirQuantidadeLivro(emprestimoViewModel.LivroId); } } if (emprestimoViewModel.Id > 0) { Usuarios usuario = _dataService.GetUsuario(emprestimoViewModel.UsuarioId); Emprestimos emprestimo = new Emprestimos(emprestimoViewModel.Id, livro, usuario, emprestimoViewModel.DataEmprestimo, emprestimoViewModel.DataDevolucao, emprestimoViewModel.Devolvido); _dataService.UpdateEmprestimo(emprestimo); } else { Usuarios usuario = _dataService.GetUsuario(emprestimoViewModel.UsuarioId); Emprestimos emprestimo = new Emprestimos(emprestimoViewModel.Id, livro, usuario, emprestimoViewModel.DataEmprestimo, emprestimoViewModel.DataDevolucao, emprestimoViewModel.Devolvido); _dataService.AddEmprestimo(emprestimo); } return(RedirectToAction("Lista")); } else { return(View()); } }
public async Task Put([FromBody] EmprestimoOrigem entity) { try { Emprestimos emp = new Emprestimos(); emp.Id = entity.Id; emp.IdAmigo = entity.IdAmigo; emp.IdJogo = entity.IdJogo; emp.DataEmprestimo = entity.DataEmprestimo; emp.IdAmigoNavigation = new Amigos(); emp.IdJogoNavigation = new Jogos(); using (var db = new DBInvilliaDesafioContext()) { //db.Entry(entity).State = EntityState.Modified; db.Entry(emp).State = EntityState.Modified; await db.SaveChangesAsync(); } } catch (Exception ex) { throw new Exception(ex.StackTrace); } }
public void UpdateEmprestimo(Emprestimos emprestimo) { this._contexto.Emprestimos.Update(emprestimo); this._contexto.SaveChanges(); }
public string Put([FromBody] Emprestimos emprestimo) { this._dataService.UpdateEmprestimo(emprestimo); return("Success"); }
public void Inserir(Emprestimos e)//Insert { contexto.Emprestimos.Add(e); contexto.SaveChanges(); }
public string Delete([FromBody] Emprestimos emprestimo) { this._dataService.DeleteEmprestimo(emprestimo.Id); return("Success"); }
public void AddEmprestimo(Emprestimos emprestimo) { this._contexto.Emprestimos.Add(emprestimo); this._contexto.SaveChanges(); }
public Emprestimos Get(int id) { Emprestimos emprestimos = this._dataService.GetEmprestimo(id); return(emprestimos); }