public int IngresarLibro(string titulo, string autor, int edicion, string editorial, int paginas, string tema) { List <Libro> libros = this.GetLibros(); int idNuevoLibro = this.UltimoCodLibro() + 1; if (string.IsNullOrEmpty(titulo) || string.IsNullOrEmpty(autor) || string.IsNullOrEmpty(editorial) || string.IsNullOrEmpty(tema)) { throw new Exception("Hay campos sin completar"); } Libro libro = new Libro(idNuevoLibro, titulo, autor, edicion, editorial, paginas, tema); foreach (Libro l in libros) { if (l.ToString() == libro.ToString()) { throw new Exception(string.Format("Ya existe el libro")); } } TransactionResult result = libroMapper.Insert(libro); if (result.IsOk) { this._libros.Add(libro); return(result.Id); } else { throw new Exception(string.Format("Ocurrió un error en el servidor. Detalle: \"{0}\"", result.Error)); } }
public int InsertarLibro(Libro L) { List <Libro> result = _mapper.TraerTodosLosLibros(); foreach (Libro Libro in result) // valida el negocio que no este ya cargado { if (Libro.Titulo == L.Titulo) { throw new Exception("El Libro ya se encuentra cargado"); } } TransactionResult resultado = _mapper.Insert(L); if (!resultado.IsOk) { throw new Exception("Hubo un error en la petición al servidor.Detalle: " + resultado.Error); } else { return(resultado.Id); } }