public ActionResult CadastroEmprestimo([FromForm] Emprestimo emprestimo) { emprestimo.DataAluguel = DateTime.Now; bibliotecaContexto.Emprestimos.Add(emprestimo); var status = bibliotecaContexto.Livros.SingleOrDefault(x => x.Id == emprestimo.IdLivro); if (status.Status == Models.Fixo.Status.Alugado) { return(NotFound()); } if (emprestimo.DataEntrega < emprestimo.DataAluguel) { return(NoContent()); } if (status != null) { status.Status = Models.Fixo.Status.Alugado; bibliotecaContexto.SaveChanges(); } bibliotecaContexto.SaveChanges(); return(View()); }
public ActionResult Salvar(Livro model) { if (model.Id.Equals(new Guid())) { model.Id = Guid.NewGuid(); model.Situacao = 'A'; bibliotecaContexto.Livros.Add(model); } else { IEnumerable <string> items = new List <string>() { "Ativo", "Inativo" }; ViewBag.Situacao = items; bibliotecaContexto.Livros.Update(model); } bibliotecaContexto.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CadastroEmprestimo([FromForm] Emprestimo aluguel) { aluguel.DataAluguel = DateTime.Now; bibliotecaContexto.Aluguels.Add(aluguel); var status = bibliotecaContexto.Livros.SingleOrDefault(x => x.Id == aluguel.IdLivro); var nomeDoCliente = bibliotecaContexto.Clientes.SingleOrDefault(x => x.Id == aluguel.IdCliente); IEnumerable <Emprestimo> clientes = bibliotecaContexto.Aluguels.ToList(); ViewBag.listofitems = new SelectList(clientes, "IdCliente", "nomeDoCliente.Nome"); if (status.Status == DesafioCast.Models.Enum.Status.Alugado) { return(NotFound()); } if (aluguel.DataEntrega < aluguel.DataAluguel) { return(NoContent()); } if (status != null) { status.Status = DesafioCast.Models.Enum.Status.Alugado; bibliotecaContexto.SaveChanges(); } bibliotecaContexto.SaveChanges(); return(View()); }
public IActionResult Post([FromBody] Livro livro) { bibliotecaContexto.Livros.Add(livro); bibliotecaContexto.SaveChanges(); return(Ok(bibliotecaContexto.Livros.ToList())); }
public IActionResult Post([FromBody] Cliente cliente) { bibliotecaContexto.Clientes.Add(cliente); bibliotecaContexto.SaveChanges(); return(Ok(bibliotecaContexto.Clientes.ToList())); }
public ActionResult CadastroCliente([FromForm] Cliente cliente) { var cpf = cliente.Cpf; cliente.Cpf = cpf.Replace(".", string.Empty).Replace("-", string.Empty); _bibliotecContexto.Clientes.Add(cliente); _bibliotecContexto.SaveChanges(); return(View()); }
public ActionResult Post([FromForm] Cliente cliente) { var index = new { id = cliente.Id + 1 }; _bibliotecaContexto.Clientes.Add(cliente); _bibliotecaContexto.SaveChanges(); return(RedirectToAction(nameof(Clientes))); }
public ActionResult Post([FromForm] Emprestimo emprestimo) { var index = new { id = emprestimo.Id + 1 }; _bibliotecaContexto.Emprestimos.Add(emprestimo); _bibliotecaContexto.SaveChanges(); return(RedirectToAction(nameof(Emprestimos))); }
public ActionResult New([FromForm] Livro livro) { var index = new { id = livro.Id + 1 }; _bibliotecaContexto.Livros.Add(livro); _bibliotecaContexto.SaveChanges(); return(RedirectToAction(nameof(GetLivros))); }
public ActionResult Excluir(string id) { Guid gId = Guid.Parse(id); Cliente cliente = (Cliente)bibliotecaContexto.Clientes.ToList().FirstOrDefault(x => x.Id == gId); bibliotecaContexto.Clientes.Remove(cliente); bibliotecaContexto.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Excluir(string id) { Guid gId = Guid.Parse(id); Emprestimo emprestimo = (Emprestimo)bibliotecaContexto.Emprestimos.ToList().FirstOrDefault(x => x.Id == gId); bibliotecaContexto.Emprestimos.Remove(emprestimo); bibliotecaContexto.SaveChanges(); return(RedirectToAction("Index")); }
public void Agregar(Prestamo prestamo) { PrestamoEntidad prestamoEntidad = BuildPrestamoEntidad(prestamo); bibliotecaContexto.Prestamos.Add(prestamoEntidad); bibliotecaContexto.SaveChanges(); }
public IActionResult Post([FromBody] Emprestimo emprestimo) { emprestimo.DataAluguel = DateTime.Now; emprestimo.DataEntrega = DateTime.Now; bibliotecaContexto.Emprestimos.Add(emprestimo); var status = bibliotecaContexto.Livros.SingleOrDefault(x => x.Id == emprestimo.IdLivro); if (status != null) { status.Status = Models.Fixo.Status.alugado; bibliotecaContexto.SaveChanges(); } bibliotecaContexto.SaveChanges(); return(Ok(bibliotecaContexto.Emprestimos.ToList())); }
public void Agregar(Prestamo prestamo) { try { PrestamoEntidad prestamoEntidad = BuildPrestamoEntidad(prestamo); bibliotecaContexto.Prestamos.Add(prestamoEntidad); bibliotecaContexto.SaveChanges(); } catch (ArgumentException e) { Console.WriteLine(e); throw; } }
public ActionResult CadastroLivro([FromForm] Livro livro) { bibliotecaContexto.Livros.Add(livro); bibliotecaContexto.SaveChanges(); return(View()); }
public void Agregar(Libro libro) { bibliotecaContexto.Libros.Add(LibroBuilder.ConvertirAEntidad(libro)); bibliotecaContexto.SaveChanges(); }
public void GuardarCambios() { ioContexto.SaveChanges(); }
public ActionResult CadastroCliente([FromForm] Cliente cliente) { bibliotecaContexto.Clientes.Add(cliente); bibliotecaContexto.SaveChanges(); return(View()); }