Beispiel #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);
        }
Beispiel #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);
                }
            }
        }
        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");
                }
            }
        }
Beispiel #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);
            }
        }
Beispiel #6
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            //Validar si el Libro existe y si esta prestado.
            if (!ExisteLibro(isbn) || EsPrestado(isbn))
            {
                throw new Exception(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
            }

            //se valida si El ISBN es Palindromo
            if (EsIsbnPalindromo(isbn))
            {
                throw new Exception(LIBRO_PALINDROMO_SOLO_BIBLIOTECA);
            }

            var libroPrestar  = libroRepositorio.ObtenerPorIsbn(isbn: isbn);
            var fechaPrestamo = new DateTime();

            var fechaEntregaMaxima = CalcularFechaEntregaMaxima(isbn: isbn, fechaPrestamo: fechaPrestamo);

            var prestamo = new Prestamo(
                fechaSolicitud: fechaPrestamo,
                libro: libroPrestar,
                fechaEntregaMaxima: fechaEntregaMaxima,
                nombreUsuario: nombreUsuario);

            this.prestamoRepositorio.Agregar(prestamo);
        }
Beispiel #7
0
        public Libro EncontrarLibroValidandoSuExistencia(string isbn)
        {
            Libro libroEncontrado = libroRepositorio.ObtenerPorIsbn(isbn);

            if (libroEncontrado == null)
            {
                throw new Exception(EL_ISBN_ES_REQUERIDO);
            }
            return(libroEncontrado);
        }
        /// <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");
            }
        }
Beispiel #9
0
        public void Prestar(string isbn, string nombreUsuario)
        {
            //variable auxiliar para obtener los caracteres del ISBN
            char[] auxISBN = isbn.ToCharArray();

            //se invierte el orden de los caracteres
            Array.Reverse(auxISBN);

            //se tiene en cuenta lo mencionado en la regla de negocio #5 (se añadie una cantidad de días por defecto para los códigos con menos de 30)
            int diasPrestamo = (isbn.Length >= 30) ? 15: DIAS_DE_PRESTAMO_DEFAULT;

            //fecha de entrega que toma valor si lleva 30+ caracteres
            DateTime?fechaEntrega = null;

            try
            {
                //se verifica si corresponde a un palíndrome
                if (isbn == new string(auxISBN))
                {
                    throw new Exception(ES_PALINDROMO);
                }

                //se verifica si esta prestado
                if (this.EsPrestado(isbn))
                {
                    throw new Exception(EL_LIBRO_NO_SE_ENCUENTRA_DISPONIBLE);
                }

                //se calcula la fecha de entrega en caso dado
                if (diasPrestamo != 0)
                {
                    fechaEntrega = CalificadorUtil.sumarDiasSinContarDomingo(DateTime.Now, diasPrestamo);
                }

                //registro del préstamo
                this.prestamoRepositorio.Agregar(
                    new Prestamo(
                        DateTime.Now,
                        libroRepositorio.ObtenerPorIsbn(isbn),
                        fechaEntrega,
                        nombreUsuario
                        )
                    );
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #10
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);
        }