예제 #1
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            if (string.IsNullOrEmpty(isbn))
            {
                throw new ArgumentException("ISBN no puede ser null");
            }

            if (string.IsNullOrEmpty(nombreUsuario))
            {
                throw new ArgumentException("El nombre del usuario no puede ser null");
            }

            if (EsPrestado(isbn))
            {
                throw new Exception(ElLibroNoSeEncuentraDisponible);
            }

            var libroaprestar = libroRepositorio.ObtenerPorIsbn(isbn);

            if (libroaprestar == null)
            {
                return;
            }
            var diaPrestamo = DateTime.Now;
            var enPrestamo  = new Prestamo(diaPrestamo, libroaprestar, nombreUsuario);

            prestamoRepositorio.Agregar(enPrestamo);
        }
예제 #2
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            DateTime?fechaEntrega;
            var      prestado = prestamoRepositorio.ObtenerLibroPrestadoPorIsbn(isbn);

            if (prestado == null)
            {
                bool esPalindroma = Palindroma(isbn);
                if (esPalindroma)
                {
                    // devolver que no se puede prestar el libro
                }

                var libro = libroRepositorio.ObtenerPorIsbn(isbn);

                //calcular fecha de entrega
                int numeroISBN = CalcularNumeroISBN(isbn);
                if (numeroISBN < 30)
                {
                    fechaEntrega = null;
                }
                else
                {
                    fechaEntrega = CalcularFechaEntrega();
                }

                //Creo el objeto para prestar el libro
                Prestamo prestarLibro = new Prestamo(DateTime.Now, libro, fechaEntrega, nombreUsuario);
                prestamoRepositorio.Agregar(prestarLibro);
            }
        }
        public void Prestar(string isbn, string nombreUsuario)
        {
            Libro libroPrestado = prestamoRepositorio.ObtenerLibroPrestadoPorIsbn(isbn);

            if (libroPrestado != null)
            {
                throw new Exception(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
            }

            Libro libroEncontrado = libroRepositorio.ObtenerPorIsbn(isbn);

            if (libroEncontrado == null)
            {
                throw new Exception(EL_LIBRO_NO_SE_ENCUENTRA_EN_EL_RESPOSITORIO);
            }
            else
            {
                bool palindormo = libroEncontrado.ValidarPalindromo();

                if (palindormo)
                {
                    throw new Exception(EL_LIBRO_ES_PALINDROMO);
                }
                else
                {
                    int      suma        = libroEncontrado.SumarString();
                    DateTime?fechaMaxima = libroEncontrado.ValidarFechaMaxima(suma);

                    Prestamo prestamo = new Prestamo(DateTime.Now, libroEncontrado, fechaMaxima, nombreUsuario);
                    prestamoRepositorio.Agregar(prestamo);
                }
            }
        }
예제 #4
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            if (isbn != null && nombreUsuario != null)
            {
                if (!EsPrestado(isbn))
                {
                    if (!ValidarPalindromo(isbn))
                    {
                        var      libro             = libroRepositorio.ObtenerPorIsbn(isbn);
                        DateTime FechaInicio       = DateTime.Now;
                        DateTime?FechaFinalEntrega = null;

                        // var FechaFinEntrega = ValidarFechaEntrega();

                        //Libro libro = new Libro(isbn, "maria", 19);
                        if (SumarDigitos(isbn) > 30)
                        {
                            FechaFinalEntrega = ValidarFechaEntrega();
                        }
                        Prestamo prestamo = new Prestamo(FechaInicio, libro, FechaFinalEntrega, nombreUsuario);
                        prestamoRepositorio.Agregar(prestamo);
                    }
                    else
                    {
                        Console.Write("Los libros palíndromos solo se pueden utilizar en la biblioteca");
                    }
                }
                else
                {
                    Console.Write("El libro ya se encuentra prestado");
                }
            }
        }
예제 #5
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            var libroExistenciaVerificada = libroRepositorio.ObtenerPorIsbn(isbn);

            if (libroExistenciaVerificada != null)
            {
                if (EsPrestado(isbn))
                {
                    if (!EsPalindroma(isbn))
                    {
                        prestamoRepositorio.Agregar(new Prestamo(DateTime.Now, libroExistenciaVerificada, CalcularFechaEntregaMaxima(isbn), nombreUsuario));
                    }
                    else
                    {
                        Console.WriteLine(LOS_LIBROS_PALINDROMOS_SOLO_EN_LA_BIBLIOTECA);
                        throw new Exception(LOS_LIBROS_PALINDROMOS_SOLO_EN_LA_BIBLIOTECA);
                    }
                }
                else
                {
                    Console.WriteLine(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
                    throw new Exception(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
                }
            }
            else
            {
                Console.WriteLine(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
                throw new Exception(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
            }
        }
예제 #6
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            Libro libroParaPrestar = EncontrarLibroValidandoSuExistencia(isbn);

            ValidarNombreUsuario(nombreUsuario);
            ValidarSiLibroPuedeSerPrestado(libroParaPrestar.Isbn);
            DateTime fechaDePrestamo = DateTime.UtcNow;
            DateTime?fechaDeEntrega  = CalcularFechaDeEntrega(libroParaPrestar.Isbn, fechaDePrestamo);
            Prestamo prestamo        = new Prestamo(fechaDePrestamo, libroParaPrestar, fechaDeEntrega.GetValueOrDefault(), nombreUsuario);

            prestamoRepositorio.Agregar(prestamo);
        }
        /// <summary>
        /// Ejecuta el préstamo de un libro.
        /// </summary>
        /// <param name="isbn">ISBN Unico del libro</param>
        /// <param name="nombreUsuario">Nombre del usuario que realiza el prestamo</param>
        public void Prestar(string isbn, string nombreUsuario)
        {
            #region Variables

            DateTime fechaEntregaMaxima = DateTime.Now;
            string   respuesta          = string.Empty;
            int      sumaIsbn           = 0;

            #endregion

            //Se obtiene el libro del repositorio para verificar existencia.
            var libroPrestamo = libroRepositorio.ObtenerPorIsbn(isbn);

            if (libroPrestamo != null)
            {
                //Se verifica si puede ser prestado o no el libro.
                if (!EsPrestado(isbn))
                {
                    //Se valida si el Isbn es palíndromo o no
                    esPalindromo = EsPalindromo(isbn);

                    if (esPalindromo)
                    {
                        throw new Exception("los libros palíndromos solo se pueden utilizar en la biblioteca");
                    }
                    else
                    {
                        //Suma caracteres Isbn
                        sumaIsbn = SumarIsbn(isbn);

                        //Calcula fecha máxima de entrega
                        fechaEntregaMaxima = CalcularFechaMaximaEntrega(sumaIsbn);
                    }

                    //Instancia objeto libro
                    Prestamo prestamoLibro = new Prestamo(DateTime.Now, libroPrestamo, fechaEntregaMaxima, nombreUsuario);

                    //Se agrega préstamo a repositorio
                    prestamoRepositorio.Agregar(prestamoLibro);
                }
                else
                {
                    throw new Exception("El libro no se encuentra disponible");
                }
            }
            else
            {
                throw new Exception("El libro solicitado no se encuentra registrado");
            }
        }
예제 #8
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            if (EsPalindromo(isbn))
            {
                throw new Exception("Los libros palindromos solo se pueden utilizar en la biblioteca");
            }

            if (EsPrestado(isbn))
            {
                throw new Exception("El libro no se encuentra disponible");
            }

            DateTime?fechaEntrega = ObtenerFechaEntregaPrestamo(isbn, DateTime.Now);

            prestamoRepositorio.Agregar(new Prestamo(DateTime.Now, libroRepositorio.ObtenerPorIsbn(isbn), fechaEntrega, nombreUsuario));
        }
        public void Prestar(string isbn, string nombreUsuario)
        {
            if (prestamoRepositorio.ObtenerLibroPrestadoPorIsbn(isbn) != null)
            {
                throw new ApplicationException(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
            }
            var libro = libroRepositorio.ObtenerPorIsbn(isbn);

            if (libro == null)
            {
                throw new ApplicationException(EL_LIBRO_NO_SE_ENCUENTRA_EN_EL_RESPOSITORIO);
            }
            if (libro.EsPalindromo())
            {
                throw new ApplicationException(EL_LIBRO_PALINDROMO_ERROR);
            }


            var      fechaMaximaEntrega = libro.AplicaFechaMaxima(libro.Isbn);
            Prestamo prestamo           = new Prestamo(DateTime.Now, libro, fechaMaximaEntrega, nombreUsuario);

            prestamoRepositorio.Agregar(prestamo);
        }