Esempio n. 1
0
        public static OnlineUserDTO FromData(OnlineUser onlineUser)
        {
            var a = onlineUser;
            var b = onlineUser.LocalLibraryMembers.Select(member => member.Reservations).SelectMany(reservation => reservation)
                    .ToList();
            var test = onlineUser.LocalLibraryMembers
                       .Select(member => member.Reservations.Select(
                                   reservation => new Reservation()
            {
                Book = reservation.Book, PickupDeadline = reservation.PickupDeadline
            }))
                       .SelectMany(reservation => reservation).ToList();

            return(new OnlineUserDTO()
            {
                Name = onlineUser.Name,
                Email = onlineUser.Email,
                LastName = onlineUser.LastName,
                Oib = onlineUser.Oib,
                Address = onlineUser.Address,
                City = onlineUser.City,
                PhoneNumber = onlineUser.PhoneNumber,

                BorrowedBooks = onlineUser.LocalLibraryMembers.Select(member => member.BatchesOfBorrowedBooks
                                                                      .Where(batch => batch.Books != null)
                                                                      .Select(batchOfBorrowedBooks => batchOfBorrowedBooks.Books.Select(
                                                                                  book => ShortBookDTO.FromData(book, batchOfBorrowedBooks.ReturnDeadline)))
                                                                      .SelectMany(book => book))
                                .SelectMany(x => x)
                                .ToList(),

                Reservations = onlineUser.LocalLibraryMembers.Select(member => member.Reservations.Select(reservation => new Reservation()
                {
                    Book = reservation.Book, PickupDeadline = reservation.PickupDeadline
                })).SelectMany(reservation => reservation).ToList()
            });
        }
Esempio n. 2
0
        public static LocalLibraryMemberDTO FromData(LocalLibraryMember member)
        {
            var borrowedBooks = member.BatchesOfBorrowedBooks
                                .Where(batch => batch.ReturnDeadline > DateTime.Now)
                                .Select(batchOfBorrowedBooks => batchOfBorrowedBooks.Books.Select(book => ShortBookDTO.FromData(book, batchOfBorrowedBooks.ReturnDeadline)))
                                .SelectMany(book => book)
                                .ToList();

            var lateBooks = member.BatchesOfBorrowedBooks
                            .Where(batch => batch.ReturnDeadline < DateTime.Now)
                            .Select(batchOfBorrowedBooks => batchOfBorrowedBooks.Books.Select(book => ShortBookDTO.FromData(book, batchOfBorrowedBooks.ReturnDeadline)))
                            .SelectMany(book => book)
                            .ToList();

            return(new LocalLibraryMemberDTO()
            {
                Name = member.Name,
                LastName = member.LastName,
                PhoneNumber = member.PhoneNumber,
                Email = member.Email,
                IsVerifiedLocal = member.IsVerifiedLocal,
                IsGuest = member.IsGuest,
                Oib = member.Oib,
                Address = member.Address,
                BarcodeNumber = member.BarcodeNumber,
                MembershipExpiryDate = member.MembershipExpiryDate,

                BorrowedBooks = borrowedBooks,

                LateBooks = lateBooks,

                Reservations = member.Reservations,

                TotalLateReturnFee = borrowedBooks.Count == 0 ? 0 : borrowedBooks.Select(book => book.LateReturnFee).Aggregate((sum, ele) => sum += ele)
            });
        }
Esempio n. 3
0
        public static LongLLMemberUserDTO FromData(LocalLibraryMember member)
        {
            return(new LongLLMemberUserDTO()
            {
                MemberId = member.Id,
                LibraryName = member.LocalLibrary.Name,
                LibraryId = member.LocalLibrary.Id,
                MembershipExpiryDate = member.MembershipExpiryDate,
                NumberOfBorrowedBooks = member.BatchesOfBorrowedBooks.Count,                /*SelectMany(batch => batch.Books).ToList().Count,*/
                NumberOfReservedBooks = member.Reservations.Count,
                LastBorrowDate = member.BatchesOfBorrowedBooks.OrderBy(book => book.PickupDate).LastOrDefault()?.PickupDate,
                LibraryOpenHours = member.LocalLibrary.OpenHours,
                LibraryAddress = member.LocalLibrary.Address,
                LibraryEmail = member.LocalLibrary.Email,
                LibraryNumber = member.LocalLibrary.Number,
                BorrowedBooks = member
                                .BatchesOfBorrowedBooks
                                .Select(batchOfBorrowedBooks => batchOfBorrowedBooks.Books.Select(book => ShortBookDTO.FromData(book, batchOfBorrowedBooks.ReturnDeadline)))
                                .SelectMany(book => book)
                                .ToList(),

                Reservations = member.Reservations
                               //.BatchesOfReservedBooks
                               //.Select(batchOfReservedBooks => batchOfReservedBooks.Books.Select(book => ShortBookDTO.FromData(book, batchOfReservedBooks.PickupDeadline)))
                               //.SelectMany(book => book)
                               //.ToList()
            });
        }