Пример #1
0
        public CustomerBookState(BookLibraryContext db, BorrowRecord borrowRecord, IEnumerable <SubscribeRecord> subscribeRecords)
        {
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }

            if (borrowRecord == null)
            {
                throw new ArgumentNullException("borrowRecord");
            }

            var currentUser = Users.Current;

            if (borrowRecord.UserId == currentUser.UserId)
            {
                InitBorrowed(borrowRecord);
            }
            else if (subscribeRecords.Any(r => r.UserId == currentUser.UserId))
            {
                InitSubscribed();
            }
            else
            {
                InitCanSubscribe(borrowRecord.BookId);
            }

            BorrowedBy   = GetUserName(db, borrowRecord.UserId);
            ReturnDate   = borrowRecord.BorrowedDate.AddDays(limitDays).ToShortDateString();
            SubscribedBy = string.Join(", ", subscribeRecords.Select(s => GetUserName(db, s.UserId)));
        }
Пример #2
0
        private BorrowListItem CreateBorrowListItem(BorrowRecord record)
        {
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }

            var state = new AdminBookState(record);
            var item  = new BorrowListItem
            {
                BorrowId   = record.BorrowRecordId.ToString(),
                BookId     = record.BookId.ToString(),
                BookNumber = record.Book.BookNumber,
                Title      = record.Book.BookType.Title,
                UserId     = record.UserId.ToString(),
                UserName   = record.User.DisplayName,
                BorrowDate = record.BorrowedDate.ToShortDateString(),
                ReturnDate = record.BorrowedDate.AddDays(limitDays).ToShortDateString(),
                State      = state.State,
                Operation  = state.Operation
            };

            return(item);
        }
Пример #3
0
        public ReadOnlyCollection <MailMessage> Verify(IEnumerable <BorrowRecord> borrowRecords)
        {
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }
            var emailContextList        = new List <MailMessage>();
            var limitDay                = DateTime.Now.AddDays(-limitDays);
            var shouldReturnBookRecords = borrowRecords.Where(br => br.BorrowedDate < limitDay);

            foreach (var shouldReturnBookRecord in shouldReturnBookRecords)
            {
                var body = string.Format(
                    "The book [{0}] you borrowed at {1} is out of date.{2} Please return it ASAP.",
                    shouldReturnBookRecord.Book.BookType.Title,
                    shouldReturnBookRecord.BorrowedDate.ToShortDateString(),
                    Environment.NewLine);
                var message = Utility.BuildMail(
                    shouldReturnBookRecord.User.EmailAdress,
                    "A borrowed book have to be returned",
                    body);
                emailContextList.Add(message);
            }

            return(emailContextList.AsReadOnly());
        }
        public ReadOnlyCollection <MailMessage> Verify(IEnumerable <BorrowRecord> borrowRecords)
        {
            int    aheadNotificationDays         = 7;
            string getAheadNotificationDaysValue = GlobalConfigReader.ReadFromLibraryServiceConfig("AheadNotification", "days");

            if (!string.IsNullOrEmpty(getAheadNotificationDaysValue))
            {
                aheadNotificationDays = Convert.ToInt32(getAheadNotificationDaysValue);
            }
            int    limitDays = 31;
            string getBorrowDayLimitValue = GlobalConfigReader.ReadFromLibraryServiceConfig("BorrowDayLimit", "days");

            if (!string.IsNullOrEmpty(getBorrowDayLimitValue))
            {
                limitDays = Convert.ToInt32(getBorrowDayLimitValue);
            }
            var emailContextList        = new List <MailMessage>();
            var limitDay                = DateTime.Now.AddDays(aheadNotificationDays - limitDays).Date;
            var shouldReturnBookRecords =
                borrowRecords.Where(br => br.BorrowedDate.Date == limitDay);

            foreach (var shouldReturnBookRecord in shouldReturnBookRecords)
            {
                var body = string.Format(
                    "The book [{0}] you borrowed will out of date at {1}.{2} Please take keep an eye open with it.",
                    shouldReturnBookRecord.Book.BookType.Title,
                    shouldReturnBookRecord.BorrowedDate.AddDays(limitDays).ToShortDateString(),
                    Environment.NewLine);
                var message = Utility.BuildMail(
                    shouldReturnBookRecord.User.EmailAdress,
                    "A borrowed book will out of data",
                    body);
                emailContextList.Add(message);
            }

            return(emailContextList.AsReadOnly());
        }