public void RegisterBooking(BookingDto NewBookingDto) { //Console.ForegroundColor = ConsoleColor.DarkYellow; //Console.WriteLine("LibraryService - Reservando libro para su préstamo \n"); //Console.ForegroundColor = ConsoleColor.White; BookingEntity bookingEntity = new BookingEntity(); bookingEntity.BookId = NewBookingDto.BookId; bookingEntity.EndBookingDate = NewBookingDto.EndBookingDate; bookingEntity.LibraryAppUsername = NewBookingDto.LibraryAppUsername; bookingEntity.StartBookingDate = NewBookingDto.StartBookingDate; _dblibrary.RegisterBooking(bookingEntity); }
/// <summary> /// /// </summary> private void BookBookimgOp() { LibraryAppUserDto libUserDto = new LibraryAppUserDto(); BookDto bookDto = new BookDto(); DateTime endBooking; string inputLine = string.Empty; Console.TreatControlCAsInput = false; do { Console.WriteLine("Introduzca el usuario: "); inputLine = Console.ReadLine(); libUserDto = _userService.GetUser(inputLine); if (libUserDto == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Nombre de usuario no válido"); Console.ForegroundColor = ConsoleColor.White; } } while (libUserDto == null); if (_libService.IsUserAllowed(libUserDto.Username)) { do { Console.WriteLine("Introduzca el libro: "); inputLine = Console.ReadLine(); bookDto = _libService.GetBook(inputLine); if (bookDto == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Nombre de libro no válido"); Console.ForegroundColor = ConsoleColor.White; } else { if(_libService.IsBooked(bookDto.BookTitle)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Libro no disponible"); Console.ForegroundColor = ConsoleColor.White; bookDto = null; } } } while (bookDto == null); Console.WriteLine("Iniciando proceso de préstamo \n"); BookingDto newBooking = new BookingDto(); bool validDAte = false; do { Console.WriteLine("Introduzca la fecha de la devolución: "); Console.WriteLine("{dd/mm/aaaa} ej: 20/08/2016"); inputLine = Console.ReadLine(); validDAte = (Common.ValidateDate(inputLine, out endBooking) && (endBooking < DateTime.Today.AddDays(30))); if (!validDAte) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Fecha de devolucióno no válida"); Console.ForegroundColor = ConsoleColor.White; } } while (!validDAte); newBooking.BookId = bookDto.Id; newBooking.LibraryAppUsername = libUserDto.Username; newBooking.StartBookingDate = DateTime.Today; newBooking.EndBookingDate = endBooking; _libService.RegisterBooking(newBooking); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Préstamo registrado correctamente \n"); Console.ForegroundColor = ConsoleColor.White; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Se ha denagado el préstamo\n"); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine("---------------------"); }
public BookingDto GetBooking(string Username, string bookTitle) { //Console.ForegroundColor = ConsoleColor.DarkYellow; //Console.WriteLine("LibraryService - Obteniendo reserva del usuario {0} del libro {1}... \n", Username, bookTitle); //Console.ForegroundColor = ConsoleColor.White; BookingEntity bookingEntity = _dblibrary.GetBooking(Username, bookTitle); BookingDto bookingDto = new BookingDto(); bookingDto.Id = bookingEntity.Id; bookingDto.BookId = bookingEntity.BookId; bookingDto.EndBookingDate = bookingEntity.EndBookingDate; bookingDto.StartBookingDate = bookingEntity.StartBookingDate; bookingDto.LibraryAppUsername = bookingEntity.LibraryAppUsername; bookingDto.UserReturnDate = bookingEntity.UserReturnDate; return bookingDto; }