Beispiel #1
0
        public async Task OnPaymentSuccessul(BookReservation reseravtion, Transaction transaction)
        {
            using (var db = new BookingContext())
            {
                var users = await db.Users.Where(x => !x.LockedOut && x.Claims.FirstOrDefault().Value == UserRoles.Admin).Select(x => new { x.Phone, x.Email, x.PhoneConfirmed, x.EmailConfirmed }).ToListAsync();

                var phoneTargets = users.Where(x => x.PhoneConfirmed);
                if (phoneTargets.Count() > 0)
                {
                    await SMSService.SendAsync(new SMS.SendSMSOptions()
                    {
                        Destinations = phoneTargets.Select(x => x.Phone).ToArray(),
                        Message      = $"Payment of {transaction.IdealAmount} GHS has been successfully made for the reservation #{reseravtion.ReferenceNo}."
                    });
                }

                var emailTargets = users.Where(x => x.EmailConfirmed);
                if (emailTargets.Count() > 0)
                {
                    await EmailService.SendAsync(new Email.SendMailOptions()
                    {
                        Destinations = emailTargets.Select(x => x.Email).ToArray(),
                        Subject      = "Payment Received",
                        IsHtml       = true,
                        Message      = $"<h3>Payment Received</h3><br/><p>Payment of <b>{transaction.IdealAmount} GHS</b></p> has been received for a new reservation #{reseravtion.ReferenceNo}",
                    });
                }
            }

            //  Broadcast signal for payment
            GlobalHost.ConnectionManager.GetHubContext <CoreHub>().Clients.All.OnReservationPaid(reseravtion.Id);
        }
        public async Task <bool> ReserveBookAsync(BaseTitleDto baseTitleDto)
        {
            var book = await this.dbContext.Books
                       .FirstOrDefaultAsync(bTitle => bTitle.Title == baseTitleDto.Title);

            var user = await this.dbContext.Users
                       .Include(uLend => uLend.BookReservations)
                       .SingleOrDefaultAsync(uId => uId.Id == baseTitleDto.UserId);

            if (book == null)
            {
                return(false);
            }
            var bookReservation = new BookReservation()
            {
                Book = book,
                User = user,
                Date = DateTime.Now
            };


            await this.dbContext.BookReservations.AddAsync(bookReservation);

            await this.dbContext.SaveChangesAsync();

            return(true);
        }
Beispiel #3
0
        public override BookReservation Insert(BookReservation toInsert)
        {
            Dictionary <string, object> Parameters = MapToDico(toInsert);

            base.Insert(Parameters);
            return(toInsert);
        }
        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>()
            });
        }
Beispiel #5
0
        public ResultDTO CloseLending(string barcode)
        {
            int             returnTime  = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            Hardbook        hardbook    = bookRepository.GetHardbook(barcode);
            BookLending     lending     = lendingRepository.GetLendingByHardbookId(hardbook.Id);
            BookReservation reservation = reservationRepository.GetReservationWithId(lending.Id);

            reservation.Status   = "Returned";
            hardbook.CanBorrowed = true;
            lending.ReturnDate   = returnTime;
            bookRepository.UpdateHardbook(hardbook);
            reservationRepository.UpdateReservations(reservation);
            lendingRepository.UpdateLending(lending);
            string message;

            if (lending.DueDate > returnTime)
            {
                message = "Trả đúng hạn";
            }
            else
            {
                TimeSpan t = TimeSpan.FromSeconds(returnTime - lending.DueDate);
                message = "Trả muộn " + t.Days + " ngày, " + t.Hours + " giờ, " + t.Minutes + " phút";
            }

            return(new ResultDTO()
            {
                Success = true,
                Message = message
            });
        }
    public boolean checkoutBookItem(BookItem bookItem)
    {
        if (this.getTotalBooksCheckedOut() >= Constants.MAX_BOOKS_ISSUED_TO_A_USER)
        {
            ShowError("The user has already checked-out maximum number of books");
            return(false);
        }
        BookReservation bookReservation = BookReservation.fetchReservationDetails(bookItem.getBarcode());

        if (bookReservation != null && bookReservation.getMemberId() != this.getId())
        {
            // book item has a pending reservation from another user
            ShowError("This book is reserved by another member");
            return(false);
        }
        else if (bookReservation != null)
        {
            // book item has a pending reservation from the give member, update it
            bookReservation.updateStatus(ReservationStatus.COMPLETED);
        }

        if (!bookItem.checkout(this.getId()))
        {
            return(false);
        }

        this.incrementTotalBooksCheckedout();
        return(true);
    }
        public ActionResult HowToGetMyOrder(string street_number, string street_name, string City, string State, string ZipCode, string Country)
        {
            Session["street_number"] = street_number;
            Session["street_name"]   = street_name;
            Session["City"]          = City;
            Session["State"]         = State;
            Session["ZipCode"]       = ZipCode;
            Session["Country"]       = Country;
            var bookingId = Convert.ToInt32(Session["reservId"].ToString());
            var userName  = User.Identity.GetUserName();
            Shipping_Address shipping_Address = new Shipping_Address();

            shipping_Address.street_number = street_number;
            shipping_Address.street_name   = street_name;
            shipping_Address.City          = City;
            shipping_Address.State         = State;
            shipping_Address.ZipCode       = ZipCode;
            shipping_Address.Country       = Country;
            shipping_Address.ReservationId = bookingId;
            shipping_Address.StudentEmail  = userName;
            db.shipping_Addresses.Add(shipping_Address);
            db.SaveChanges();
            BookReservation bookReservation = db.BookReservations.Find(bookingId);

            bookReservation.Status          = "Delivery";
            db.Entry(bookReservation).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public void ReserveBook(Account user, Book book)
        {
            char bookLetter = book.Title.ToUpper()[0];

            foreach (var rack in dbContext.Racks)
            {
                if (rack.Letters.Any(rackLetter => rackLetter.Letter == bookLetter))
                {
                    var bookItem = rack.BookItems.FirstOrDefault(bItem => bItem.Book.Id == book.Id &&
                                                                 !dbContext.BookReservations.Any(bReserve => bReserve.BookItemId == bItem.Id));

                    var bookReserv = new BookReservation
                    {
                        BookItemId = bookItem.Id,
                        AccountId  = user.Id,
                        Date       = DateTime.Now
                    };

                    dbContext.BookReservations.Add(bookReserv);
                    break;
                }
            }

            dbContext.SaveChanges();
        }
        public static void SendBookingEmail(BookReservation bookReservation)
        {
            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}," +
                       $" Your book reservation has been successfully made /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 confrims your reservation,please ensure that you return the book on time to prevent penalties. Should you have anny further enquiries feel free to contact us.";

            EmailService emailService = new EmailService();

            emailService.SendEmail(new EmailContent()
            {
                mailTo          = mailTo,
                mailCc          = new List <MailAddress>(),
                mailSubject     = $"Book Reservation Confirmation!!  | 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>()
            });
        }
        public ActionResult DeleteConfirmed(int id)
        {
            BookReservation bookReservation = db.BookReservations.Find(id);

            db.BookReservations.Remove(bookReservation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #11
0
 private BookReservation mapBookReservation(BookReservation br)
 {
     return(new BookReservation()
     {
         ID = br.ID,
         reservatedBooks = br.reservatedBooks,
         user = br.user
     });
 }
Beispiel #12
0
 public IActionResult AddBookReservation([FromBody] BookReservation br)
 {
     if (br == null)
     {
         return(BadRequest());
     }
     _bookReservations.Add(br);
     return(CreatedAtRoute("GetById", new { id = br.ID }, br));
 }
Beispiel #13
0
        private Dictionary <string, object> MapToDico(BookReservation toInsert)
        {
            Dictionary <string, object> p = new Dictionary <string, object>();

            p["_idReader"]       = toInsert.IdReader;
            p["IdBookCopy"]      = toInsert.IdBookCopy;
            p["ReservationDate"] = toInsert.ReservationDate;
            return(p);
        }
 public ActionResult Edit([Bind(Include = "ReservationId,BookId,ReservationDate,StudentEmail,CollectionDate,ReturnDate,Status")] BookReservation bookReservation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookReservation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bookReservation));
 }
        public ResultDTO CreateReservation(Guid accountId, Guid bookId)
        {
            UpdateReservation(bookId);
            BookReservation reservation = reservationRepository.GetReservationWithStatus(accountId, bookId, "Pending", "Accepted", "Borrowing", "Overdue");

            if (reservation != null)
            {
                return(new ResultDTO()
                {
                    Success = false,
                    Message = "Đã có yêu cầu đặt sách này"
                });
            }

            reservation = new BookReservation()
            {
                Id              = Guid.NewGuid(),
                AccountId       = accountId,
                BookId          = bookId,
                ReservationDate = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()
            };

            if (reservationRepository.CountReservationWithStatus(bookId, "Accepted") < bookRepository.CountAvalableHardbook(bookId))
            {
                reservation.Status = "Accepted";
            }
            else
            {
                reservation.Status = "Pending";
            }

            if (reservationRepository.CreateReservation(reservation))
            {
                // Auto accept
                if (reservation.Status.Equals("Accepted"))
                {
                    return(lendingService.AssignHardbook(accountId, bookRepository.ListAvailableHardbooks(bookId).FirstOrDefault().Barcode));
                }

                return(new ResultDTO()
                {
                    Success = true,
                    Message = "Đặt sách thành công"
                });
            }
            else
            {
                return(new ResultDTO()
                {
                    Success = false,
                    Message = "Lỗi hệ thống"
                });
            }
        }
        public ActionResult PlaceOrder(string id)
        {
            var userName  = User.Identity.GetUserName();
            var bookingID = db.BookReservations.Where(x => x.StudentEmail == userName).Select(x => x.ReservationId).Max();

            BookReservation bookReservation = db.BookReservations.Find(bookingID);

            bookReservation.Status          = "Collect";
            db.Entry(bookReservation).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public Options Execute(ICommandArgs commandArgs)
        {
            if (commandArgs.Library.System.BookLendings.Count(u => u.User == commandArgs.Users.CurrentAccount) == 5)
            {
                Console.WriteLine("You cannot take more than 5 books");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            Console.WriteLine("Enter ISBN of the book you want:");
            var bookIsbn = Console.ReadLine();

            var book = commandArgs.Library.Books.FirstOrDefault(b => b.ISBN == bookIsbn);

            if (book == null)
            {
                Console.WriteLine($"Book with the following ISBN: {bookIsbn} was not found");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            var bookReservation = new BookReservation();
            var user            = commandArgs.Users.CurrentAccount;

            if (!commandArgs.Library.LendBook(user, book))
            {
                var option = commandArgs.MultipleChoice(title: "The book has no other copies left!" +
                                                        " Do you want to reserve?", new List <String>
                {
                    "Reserve",
                    "Cancel"
                });
                if (option == "Reserve")
                {
                    if (commandArgs.Library.System.BookLendings.Count(b => b.User == commandArgs.Users.CurrentAccount) == 5)
                    {
                        Console.WriteLine("You cannot reserve more than 5 books");
                        Console.ReadKey();
                        return(Options.HomeMenu);
                    }
                    commandArgs.Library.ReserveBook(user, book);
                    Console.WriteLine($"You reserved book: {book} {DateTime.Now}");
                    Console.ReadKey();
                }
            }
            else
            {
                Console.WriteLine($"You checked out book: {book} {DateTime.Now}");
                Console.ReadKey();
            }
            return(Options.HomeMenu);
        }
Beispiel #18
0
        public override Options Execute(ICommandArgs commandArgs)
        {
            Console.WriteLine("Enter the ISBN of the book you want to return");
            var bookIsbn = Console.ReadLine();

            var bookLending = commandArgs.LibrarySystemContext.BookLendings
                              .FirstOrDefault(b => b.BookItem.Book.ISBN == bookIsbn &&
                                              b.User == commandArgs.UsersService.CurrentAccount);

            if (bookLending == null)
            {
                Console.WriteLine($"Book with the following ISBN {bookIsbn} was not found!");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            if (!commandArgs.LibraryService.SystemService.ValidateLendPeriod(bookLending))
            {
                var fine = commandArgs.LibraryService.SystemService.CalculateFine(bookLending);
                Console.WriteLine($"You must pay {fine} for the overdue period");
                commandArgs.UsersService.CurrentAccount.CanCheckOutBook = false;
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            commandArgs.LibraryService.ReturnBook(bookLending);
            Console.WriteLine("The book was returned successfully");
            Console.ReadKey();

            var reservations = commandArgs.LibrarySystemContext.BookReservations.Where(b => b.BookItem.Book.ISBN == bookIsbn);

            var firstReservation = new BookReservation()
            {
                Date = DateTime.Now
            };

            if (reservations.Count() > 0)
            {
                foreach (var reservation in reservations)
                {
                    if (firstReservation.Date > reservation.Date)
                    {
                        firstReservation = reservation;
                    }
                }

                commandArgs.LibrarySystemContext.BookReservations.Remove(firstReservation);
            }
            commandArgs.LibrarySystemContext.BookReservations.Remove(firstReservation);

            return(Options.HomeMenu);
        }
    public void returnBookItem(BookItem bookItem)
    {
        this.checkForFine(bookItem.getBarcode());
        BookReservation bookReservation = BookReservation.fetchReservationDetails(bookItem.getBarcode());

        if (bookReservation != null)
        {
            // book item has a pending reservation
            bookItem.updateBookItemStatus(BookStatus.RESERVED);
            bookReservation.sendBookAvailableNotification();
        }
        bookItem.updateBookItemStatus(BookStatus.AVAILABLE);
    }
Beispiel #20
0
        // GET: BookReservations/Create
        public ActionResult Create()
        {
            var books    = db.Books.ToList();
            var students = db.Students.ToList();

            var bookrev = new BookReservation
            {
                BookNameCollection    = GetBookNames(books),
                StudentNameCollection = GetStudentNames(students)
            };

            return(View(bookrev));
        }
 public bool CreateReservation(BookReservation reservation)
 {
     try
     {
         DbContext.BookReservation.Add(reservation);
         DbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        // GET: BookReservations/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookReservation bookReservation = db.BookReservations.Find(id);

            if (bookReservation == null)
            {
                return(HttpNotFound());
            }
            return(View(bookReservation));
        }
Beispiel #23
0
        public override Options Execute(ICommandArgs commandArgs)
        {
            if (commandArgs.LibraryService.SystemService.BookLendings.Count(b => b.User == commandArgs.UsersService.CurrentAccount) == 5)
            {
                Console.WriteLine("You cannot reserve more than 5 books");
                Console.ReadKey();
                return(Options.HomeMenu);
            }
            Console.WriteLine("Enter ISBN of the book you want:");
            var bookIsbn = Console.ReadLine();

            var book = commandArgs.LibraryService.Books.FirstOrDefault(b => b.ISBN == bookIsbn);

            if (book == null)
            {
                Console.WriteLine($"Book with the following ISBN: {bookIsbn} was not found");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            var bookReservation = new BookReservation();
            var user            = commandArgs.UsersService.CurrentAccount;

            var option = this.MultipleChoice(title: " Do you want to reserve?", new List <string>
            {
                "Reserve",
                "Cancel"
            });

            if (option == "Reserve")
            {
                if (commandArgs.LibraryService.SystemService.BookLendings.Count(b => b.User == commandArgs.UsersService.CurrentAccount) == 5)
                {
                    Console.WriteLine("You cannot reserve more than 5 books");
                    Console.ReadKey();
                    return(Options.HomeMenu);
                }
                commandArgs.LibraryService.ReserveBook(user, book);
                Console.WriteLine($"You reserved book: {book} {DateTime.Now}");
                Console.ReadKey();
            }
            if (option == "Cancel")
            {
                Console.WriteLine("You canceled your reservation!");
                Console.ReadKey();
                return(Options.HomeMenu);
            }

            return(Options.HomeMenu);
        }
Beispiel #24
0
        public static bool CheckBooking(BookReservation booking)
        {
            bool result    = false;
            var  dbRecords = db.BookReservations.Where(x => x.CollectionDate == booking.CollectionDate).ToList();

            foreach (var item in dbRecords)
            {
                if (booking.BookId == booking.BookId)
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Beispiel #25
0
        public ActionResult SMSReminder(int?id)
        {
            var message = string.Empty;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookReservation bookReservation = db.BookReservations.Find(id);

            message = "Hi, " + bookReservation.StudentName + "\n\nPlease note your book " + bookReservation.BookName + " is over due.\nPlease return it as soon as possible.";
            bookReservation.SMSMessage = message;

            return(View(bookReservation));
        }
Beispiel #26
0
        public ActionResult Create([Bind(Include = "ReservationId,BookName,StudentName,CollectionDate,ReturnDate,Status")] BookReservation bookReservation)
        {
            bookReservation.CollectionDate = DateTime.Now.Date;
            bookReservation.ReturnDate     = DateTime.Now.Date.AddDays(14);
            bookReservation.Status         = Enums.BookStatus.Booked.ToString();

            if (ModelState.IsValid)
            {
                db.BookReservations.Add(bookReservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bookReservation));
        }
        public async Task <GetReservationsSummaryResponseItem> AddReservationAsync(PostReservationRequest request)
        {
            var reservation = new BookReservation
            {
                For     = request.For,
                BookIds = request.Books,
                Status  = ReservationStatus.Pending
            };

            _context.Reservations.Add(reservation);
            await _context.SaveChangesAsync();

            await _reservationProcessor.AddWorkAsync(reservation);

            return(_mapper.Map <GetReservationsSummaryResponseItem>(reservation));
        }
Beispiel #28
0
 private void button11_Click(object sender, EventArgs e)
 {
     if (OverDueChk.Text.Contains("연체"))
     {
         MessageBox.Show("연체된 도서가 존재합니다.");
         return;
     }
     try
     {
         BookReservation bookReservation = new BookReservation(bookListTable.Rows[bookListTable.CurrentRow.Index].Cells[1].Value.ToString(), bookListTable.Rows[bookListTable.CurrentRow.Index].Cells[0].Value.ToString(), id);
         bookReservation.Show();
     }
     catch (Exception a)
     {
     }
 }
Beispiel #29
0
 public List <LendingDTO> ListLendings(Guid accountId)
 {
     return(lendingRepository.ListLendings(accountId).Select(x =>
     {
         BookReservation reservation = reservationRepository.GetReservationWithId(x.Id);
         Book book = bookRepository.GetBookById(reservation.BookId);
         return new LendingDTO()
         {
             BorrowedDate = x.BorrowedDate,
             DueDate = x.DueDate,
             BookId = book.Id,
             Image = book.Image,
             Title = book.Title,
             Status = Utility.TranslateStatusToVI(reservation.Status)
         };
     }).ToList());
 }
Beispiel #30
0
        public ActionResult SMSReminder([Bind(Include = "ReservationId,BookName,StudentName,CollectionDate,ReturnDate,Status,SMSMessage")] BookReservation bookReservation)
        {
            var client = new Client(creds: new Nexmo.Api.Request.Credentials
            {
                ApiKey    = "7692f400",
                ApiSecret = "Zua8eJBJEcveP0Zn"
            });
            var results = client.SMS.Send(request: new SMS.SMSRequest
            {
                from = "DGHS",
                to   = "27817375820",
                //update to include book information

                text = bookReservation.SMSMessage
            });

            return(View(bookReservation));
        }