Пример #1
0
        public void TestCreate()
        {
            Genero genero = NovoGenero();

            repositoryGenero.Add(genero);
            Assert.NotEqual(0, genero.Id);

            Autor autor = NovoAutor();

            repositoryAutor.Add(autor);
            Assert.NotEqual(0, autor.Id);

            Livro livro = NovoLivro(genero.Id, autor.Id);

            repositoryLivro.Add(livro);
            Assert.NotEqual(0, livro.Id);

            Usuario usuario = NovoUsuario();

            repositoryUsuario.Add(usuario);
            Assert.NotEqual(0, usuario.Id);

            Emprestimo emprestimo = NovoEmprestimo(usuario.Id, livro.Id);

            repository.Add(emprestimo);
            Assert.NotEqual(0, emprestimo.Id);

            repository.Remove(emprestimo.Id);
            repositoryUsuario.Remove(usuario.Id);
            repositoryLivro.Remove(livro.Id);
            repositoryAutor.Remove(autor.Id);
            repositoryGenero.Remove(genero.Id);
        }
        public ActionResult <EmprestimoViewModel> Create(SaveEmprestimoViewModel saveViewModel)
        {
            var emprestimo = _emprestimoRepository.Add(_mapper.Map <Emprestimo>(saveViewModel));

            if (emprestimo == null)
            {
                return(BadRequest());
            }

            return(Ok(_mapper.Map <EmprestimoViewModel>(emprestimo)));
        }
Пример #3
0
    protected void selecionarEquipamento_Click(object sender, EventArgs e)
    {
        if (char.IsNumber(txtQtdeEmprestimo.Text, 0) && char.IsNumber(lblIdClient.Text, 0))
        {
            emprestimoRepository = new EmprestimoRepository();

            emprestimoModel.emprestimo _emprestimo = new emprestimoModel.emprestimo();

            _emprestimo.DataEmprestimo = DateTime.Now;
            _emprestimo.IdCliente      = int.Parse(lblIdClient.Text);
            _emprestimo.IdEquipamento  = int.Parse(dropEquipamento.SelectedItem.Value);
            _emprestimo.Status         = 1;
            _emprestimo.Quantidade     = int.Parse(txtQtdeEmprestimo.Text);

            var id = 1;

            if (emprestimoRepository.FindAll().Count() > 0)
            {
                id = emprestimoRepository.FindAll().Count() + 1;
            }



            _emprestimo.IdEmprestimo = id;



            emprestimoRepository.Add(_emprestimo);


            var _emprestimos = emprestimoRepository.FindAllByIdClient(int.Parse(lblIdClient.Text));

            gridEmprestimo.DataSource = _emprestimos;
            gridEmprestimo.DataBind();
        }
        else
        {
            Response.Write("Consulte o cliente e insira a quantidade, campo deve ser numerico.");
        }
    }
        public HttpResponseMessage AddEmprestimo()
        {
            Emprestimo emprestimo = new Emprestimo();

            List <Livro> livros = null;

            Usuario usuario = null;

            emprestimo.DiaDevolucao  = DateTime.Now.AddDays(5);
            emprestimo.DiaEmprestimo = DateTime.Now;

            using (var repository = new LivroRepository())
            {
                livros = repository.ListAll();
            }



            emprestimo.Livros = livros;

            emprestimo.Multa      = 0;
            emprestimo.Quantidade = livros.Count();

            using (var repository = new UsuarioRepository())
            {
                usuario = repository.GetById(2);
            }


            emprestimo.Usuario = usuario;

            using (var repository = new EmprestimoRepository())
            {
                repository.MarkStates(System.Data.Entity.EntityState.Unchanged, emprestimo);
                repository.Add(emprestimo);
            }


            return(Request.CreateResponse(HttpStatusCode.OK, "Adicionou"));
        }
Пример #5
0
 public void AddEmprestimo(Emprestimo emprestimo)
 {
     _emprestimoRepository.Add(emprestimo);
 }