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());
        }
Exemple #2
0
        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"));
        }
Exemple #3
0
        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()));
        }
Exemple #5
0
        public IActionResult Post([FromBody] Cliente cliente)
        {
            bibliotecaContexto.Clientes.Add(cliente);

            bibliotecaContexto.SaveChanges();

            return(Ok(bibliotecaContexto.Clientes.ToList()));
        }
Exemple #6
0
        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)));
        }
Exemple #8
0
        public ActionResult Post([FromForm] Emprestimo emprestimo)
        {
            var index = new { id = emprestimo.Id + 1 };

            _bibliotecaContexto.Emprestimos.Add(emprestimo);

            _bibliotecaContexto.SaveChanges();

            return(RedirectToAction(nameof(Emprestimos)));
        }
Exemple #9
0
        public ActionResult New([FromForm] Livro livro)
        {
            var index = new { id = livro.Id + 1 };

            _bibliotecaContexto.Livros.Add(livro);

            _bibliotecaContexto.SaveChanges();

            return(RedirectToAction(nameof(GetLivros)));
        }
Exemple #10
0
        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"));
        }
Exemple #11
0
        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()));
        }
Exemple #14
0
 public void Agregar(Prestamo prestamo)
 {
     try
     {
         PrestamoEntidad prestamoEntidad = BuildPrestamoEntidad(prestamo);
         bibliotecaContexto.Prestamos.Add(prestamoEntidad);
         bibliotecaContexto.SaveChanges();
     }
     catch (ArgumentException e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemple #15
0
 public ActionResult CadastroLivro([FromForm] Livro livro)
 {
     bibliotecaContexto.Livros.Add(livro);
     bibliotecaContexto.SaveChanges();
     return(View());
 }
Exemple #16
0
 public void Agregar(Libro libro)
 {
     bibliotecaContexto.Libros.Add(LibroBuilder.ConvertirAEntidad(libro));
     bibliotecaContexto.SaveChanges();
 }
Exemple #17
0
 public void GuardarCambios()
 {
     ioContexto.SaveChanges();
 }
Exemple #18
0
 public ActionResult CadastroCliente([FromForm] Cliente cliente)
 {
     bibliotecaContexto.Clientes.Add(cliente);
     bibliotecaContexto.SaveChanges();
     return(View());
 }