public void Salvar(Emprestimo emprestimo)
        {
            if (emprestimo != null && emprestimo.Validar())
            {
                emprestimo.DataEmprestimo = emprestimo.DataEmprestimo == DateTime.MinValue
                    ? DateTime.Now
                    : emprestimo.DataEmprestimo;

                emprestimo.Amigo  = _amigoBusiness.Obter(emprestimo.Amigo.Codigo);
                emprestimo.Titulo = _tituloBusiness.Obter(emprestimo.Titulo.Codigo);
                if (emprestimo.Codigo > 0)
                {
                    AlterarTituloEmprestado(emprestimo);
                }
                else
                {
                    _emprestimoData.Salvar(emprestimo);
                }
                if (emprestimo.DataDevolucao == null)
                {
                    emprestimo.Titulo.IsEmprestado = "S";
                    _tituloBusiness.Salvar(emprestimo.Titulo);
                }
            }
            else
            {
                throw new ProjetoException("Dados inválidos ao salvar o empréstimo.");
            }
        }
Ejemplo n.º 2
0
 public object PostJogo(Titulo jogo)
 {
     if (jogo != null)
     {
         jogo.Usuario = User.Identity.Name;
         try
         {
             _tituloBusiness.Salvar(jogo);
             return(new { operacaoConcluidaComSucesso = true });
         }
         catch (ProjetoException pe)
         {
             return(new { operacaoConcluidaComSucesso = false, mensagem = pe.Message });
         }
     }
     return(new { operacaoConcluidaComSucesso = false });
 }