コード例 #1
0
        public static void PenaltyEmail(BookReservation bookReservation, ReservationPenalty reservationPenalty)
        {
            var book         = db.Books.Find(bookReservation.BookId);
            var bookCategory = db.BookCategories.Find(book.CategoryId);
            var mailTo       = new List <MailAddress>();

            mailTo.Add(new MailAddress(bookReservation.StudentEmail, bookReservation.StudentEmail));
            var body = $"Good Day {bookReservation.StudentEmail}," +
                       $" THe following reservation is overdue by {reservationPenalty.NumberOfDays} days /n" +
                       $" -----------------------------------Reservation Details---------------------------------" +
                       $"Book Title : {book.Title} /n" +
                       $"Book Title : {book.Genre} /n" +
                       $"Book Title : {bookCategory.CategoryName} /n" +
                       $"CollectionDate : {bookReservation.CollectionDate} /n" +
                       $"Return Date : {bookReservation.ReturnDate} /n" +
                       $"<br/> This email is to notify you that you've fined {reservationPenalty.PenaltyCost.ToString("c")} for not returning the book on time .";

            EmailService emailService = new EmailService();

            emailService.SendEmail(new EmailContent()
            {
                mailTo          = mailTo,
                mailCc          = new List <MailAddress>(),
                mailSubject     = $"Book Reservation Overdue!!  | Ref No.:{bookReservation.StudentEmail}{book.BookId}",
                mailBody        = body,
                mailFooter      = $"<br/> Kind Regards, <br/> <b>Your Friendly Librarian </b>",
                mailPriority    = MailPriority.High,
                mailAttachments = new List <Attachment>()
            });
        }
コード例 #2
0
        public static void CheckOverDue(int id)
        {
            var reservation = db.BookReservations.Find(id);

            if (DateTime.Now.Date > reservation.ReturnDate.Date)
            {
                var numberOfDays    = CalcNoOfDays(reservation.ReturnDate);
                var penaltySettings = db.PenaltyCosts.Where(x => x.NumberOfDays == numberOfDays).FirstOrDefault();
                var penaltyRecord   = new ReservationPenalty();
                penaltyRecord.NumberOfDays  = numberOfDays;
                penaltyRecord.ReservationId = (int)id;
                penaltyRecord.PenaltyCost   = penaltySettings.CostPrice;
                db.ReservationPenalties.Add(penaltyRecord);
                db.SaveChanges();
                AdAmount(penaltySettings.CostPrice, reservation.StudentEmail);
                ChangeReservationStatus(id, "Over Due");
                EmailSender1.PenaltyEmail(reservation, penaltyRecord);
            }
        }