public ActionResult PickUp(BookRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookRent bookRent = db.BookRental.Find(model.Id);

            bookRent.Status    = BookRent.StatusEnum.Rented;
            bookRent.StartDate = DateTime.Now;

            if (bookRent.RentalDuration == StaticDetails.SixMonthCount)
            {
                bookRent.ScheduleEndDate = DateTime.Now.AddMonths(Convert.ToInt32(StaticDetails.SixMonthCount));
            }
            else
            {
                bookRent.ScheduleEndDate = DateTime.Now.AddMonths(Convert.ToInt32(StaticDetails.OneMonthCount));
            }

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Return(BookRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                BookRent bookRent = db.BookRental.Find(model.Id);
                bookRent.Status = BookRent.StatusEnum.Closed;

                bookRent.AdditionalCharge = model.AdditionalCharge;
                bookRent.RentalPrice      = bookRent.RentalPrice + (double)bookRent.AdditionalCharge;
                Book bookInDb = db.Books.Find(bookRent.BookId);

                var userInDb = db.Users.Single(u => u.Id == bookRent.UserId);
                if (userInDb.RentalCount == 11)
                {
                    userInDb.RentalCount = 0;
                }
                else
                {
                    userInDb.RentalCount++;
                }

                bookInDb.Avaibility += 1;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public ActionResult Create(BookRentalViewModel bookRent)
        {
            if (ModelState.IsValid)
            {
                var email = bookRent.email;

                var userDetails = from u in db.Users
                                  where (email.Equals(email))
                                  select new
                {
                    u.Id
                };

                var ISBN = bookRent.ISBN;

                Book bookSelected = db.Books.Where(b => b.ISBN == (ISBN)).FirstOrDefault();

                var rentalDuration = bookRent.rentalDuration;

                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes on u.membershipTypeId equals m.membershipTypesIdPK
                                 where u.Email.Equals(email)
                                 select new
                {
                    m.chargeRateOneMonth,
                    m.chargeRateSixMonth
                };

                var oneMonthRental = Convert.ToDouble(bookSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].chargeRateOneMonth) / 100;
                var sixMonthRental = Convert.ToDouble(bookSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].chargeRateSixMonth) / 100;

                double rentalPrice = 0;

                if (bookRent.rentalDuration == SD.sixMonthCount)
                {
                    rentalPrice = sixMonthRental;
                }
                else
                {
                    rentalPrice = oneMonthRental;
                }

                BookRent ModelToAddToDB = new BookRent
                {
                    bookRentId       = bookSelected.bookIdPK,
                    rentalPrice      = rentalPrice,
                    scheduledEndDate = bookRent.scheduledEndDate,
                    rentalDuration   = bookRent.rentalDuration,
                    Status           = BookRent.statusEnum.approved,
                    userRentId       = userDetails.ToList()[0].Id
                };

                bookSelected.availability -= 1;
                db.BookRents.Add(ModelToAddToDB);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Esempio n. 4
0
        public ActionResult Create(BookRentalViewModel bookRent)
        {
            if (ModelState.IsValid)
            {
                var email       = bookRent.Email;
                var userDetails = from u in db.Users
                                  where u.Email.Equals(email)
                                  select new { u.Id, u.FirstName, u.LastName, u.BirthDate };

                var  ISBN         = bookRent.ISBN;
                Book bookSelected = db.Books.Where(b => b.ISBN == ISBN).FirstOrDefault();

                var rentalDuration = bookRent.RentalDuration;
                var chargeRate     = from u in db.Users
                                     join m in db.MembershipTypes on u.MembershipTypeId equals m.Id
                                     where u.Email.Equals(email)
                                     select new { m.ChargeRateOneMonth, m.ChargeRateSixMonth };

                var oneMonthRental = Convert.ToDouble(bookSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                var sixMonthRental = Convert.ToDouble(bookSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;

                double rentalPr = 0;

                if (bookRent.RentalDuration == SD.SixMonthCount)
                {
                    rentalPr = sixMonthRental;
                }
                else
                {
                    rentalPr = oneMonthRental;
                }
                var userInDb = db.Users.SingleOrDefault(u => u.Email == email);
                //if (userInDb.RentalCount == 10)
                //{
                //    userInDb.RentalCount++;
                //    rentalPr = rentalPr - (rentalPr * 20 / 100);
                //}
                BookRent modelToAddToDb = new BookRent
                {
                    BookId           = bookSelected.Id,
                    RentalPrice      = rentalPr,
                    ScheduledEndDate = bookRent.ScheduledEndDate,
                    RentalDuration   = bookRent.RentalDuration,
                    Status           = BookRent.StatusEnum.Approved,
                    UserId           = userDetails.ToList()[0].Id
                };

                bookSelected.Avaibility -= 1;
                db.BookRental.Add(modelToAddToDb);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Esempio n. 5
0
 //Get: Create
 public ActionResult Create(string tittle = null, string ISBN = null)
 {
     if (tittle != null & ISBN != null)
     {
         BookRentalViewModel model = new BookRentalViewModel
         {
             tittle = tittle,
             ISBN   = ISBN
         };
     }
     return(View());
 }
 public ActionResult Create(string title = null, string isbn = null)
 {
     if (title != null && isbn != null)
     {
         BookRentalViewModel model = new BookRentalViewModel
         {
             Title = title,
             ISBN  = isbn
         };
     }
     return(View(new BookRentalViewModel()));
 }
Esempio n. 7
0
        public ActionResult Create(BookRentalViewModel bookRent)
        {
            if (ModelState.IsValid)
            {
                var email = bookRent.Email;

                var userDetail = from u in db.Users
                                 where u.Email.Equals(email)
                                 select new { u.Id };

                var isbn = bookRent.ISBN;

                Book bookSelected = db.Books.Where(b => b.ISBN.Equals(isbn)).FirstOrDefault();

                var rentalDuration = bookRent.RentalDuration;

                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes on u.MembershipTypeId equals m.Id
                                 where u.Email.Equals(email)
                                 select new { m.ChargeRateOneMonth, m.ChargeRateSixMonth };

                var oneMonthRental = Convert.ToDouble(bookSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                var sixMonthRental = Convert.ToDouble(bookSelected.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;

                double rentalPrice = 0;

                if (bookRent.RentalDuration == SD.SixMonth)
                {
                    rentalPrice = sixMonthRental;
                }
                else
                {
                    rentalPrice = oneMonthRental;
                }

                BookRent model = new BookRent
                {
                    BookId           = bookSelected.Id,
                    RentalPrice      = rentalPrice,
                    ScheduledEndDate = bookRent.ScheduledEndDate,
                    RentalDuration   = bookRent.RentalDuration,
                    Status           = BookRent.StatusEnum.Approved,
                    UserId           = userDetail.ToList()[0].Id
                };

                bookSelected.Avaibility -= 1;
                db.BookRental.Add(model);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View());
        }
Esempio n. 8
0
 public ActionResult Approve(BookRentalViewModel model)
 {
     if (model.Id == 0)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     if (ModelState.IsValid)
     {
         BookRent bookRent = db.BookRental.Find(model.Id);
         bookRent.Status = BookRent.StatusEnum.Approved;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 9
0
        // GET: BookDetail
        public ActionResult Index(int id)
        {
            var userid    = User.Identity.GetUserId();
            var user      = db.Users.FirstOrDefault(u => u.Id == userid);
            var bookModel = db.Books.Include(b => b.Genre).SingleOrDefault(b => b.Id == id);

            var rentalPrice    = 0.0;
            var oneMonthRental = 0.0;
            var sixMonthRental = 0.0;

            //var rentalCount = 0;

            if (userid != null && !User.IsInRole(SD.AdminUserRole))
            {
                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes on u.MembershipTypeId equals m.Id
                                 where u.Id.Equals(userid)
                                 select new { m.ChargeRateOneMonth, m.ChargeRateSixMonth };

                oneMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                sixMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;
                //rentalCount = Convert.ToInt32(chargeRate.ToList()[0].RentalCount);
            }

            BookRentalViewModel model = new BookRentalViewModel
            {
                BookId              = bookModel.Id,
                ISBN                = bookModel.ISBN,
                Author              = bookModel.Author,
                Avaibility          = bookModel.Avaibility,
                DateAdded           = bookModel.DateAdded,
                Description         = bookModel.Description,
                Genre               = db.Genres.FirstOrDefault(g => g.Id.Equals(bookModel.GenreId)),
                GenreId             = bookModel.GenreId,
                ImageUrl            = bookModel.ImageUrl,
                Pages               = bookModel.Pages,
                Price               = bookModel.Price,
                Publisher           = bookModel.Publisher,
                PublicationDate     = bookModel.PublicationDate,
                ProductDimensions   = bookModel.ProductDimensions,
                Title               = bookModel.Title,
                UserId              = userid,
                RentalPrice         = rentalPrice,
                RentalPriceOneMonth = oneMonthRental,
                RentalPriceSixMonth = sixMonthRental,
                //RentalCount = rentalCount
            };

            return(View(model));
        }
Esempio n. 10
0
        // GET: BOOK INFORMATION
        public ActionResult Index(int id)
        {
            var userid            = User.Identity.GetUserId();
            var user              = db.Users.FirstOrDefault(u => u.Id == userid);
            var bookModel         = db.Books.Include(b => b.Genre).SingleOrDefault(b => b.ID == id);
            var rentalPrice       = 0.0;
            var sixMonthRental    = 0.0;
            var twelveMonthRental = 0.0;

            //if the user is not an admin
            if (userid != null && !User.IsInRole(StaticDetails.AdminUserRole))
            {
                //retrieves the charge rates for 6 months and 12 months
                var chargeRate = from u in db.Users
                                 join m in db.Memberships on u.MembershipID equals m.ID
                                 where u.Id.Equals(userid)
                                 select new { m.ChargeRateSixMonth, m.ChargeRateTwelveMonth };

                //calculates the price of 6 month and 12 month charge rates
                sixMonthRental    = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;
                twelveMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateTwelveMonth) / 100;
            }

            //converts BookRentalViewModel in object model and returns to view
            BookRentalViewModel model = new BookRentalViewModel
            {
                BookID          = bookModel.ID,
                ISBN            = bookModel.ISBN,
                Author          = bookModel.Author,
                Availability    = bookModel.Availability,
                DateAdded       = bookModel.DateAdded,
                Description     = bookModel.Description,
                Genre           = db.Genres.FirstOrDefault(g => g.ID.Equals(bookModel.GenreID)),
                GenreID         = bookModel.GenreID,
                ImageUrl        = bookModel.ImageUrl,
                Pages           = bookModel.Pages,
                Price           = bookModel.Price,
                Publisher       = bookModel.Publisher,
                PublicationDate = bookModel.PublicationDate,
                //ProductDimensions = bookModel.ProductDimensions,
                Title                  = bookModel.Title,
                UserID                 = userid,
                RentalPrice            = rentalPrice,
                RentalPriceSixMonth    = sixMonthRental,
                RentalPriceTwelveMonth = twelveMonthRental
            };

            return(View(model));
        }
Esempio n. 11
0
        // GET: BookDetail
        public ActionResult Index(int id)
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.FirstOrDefault(u => u.Id == userId);

            var bookModel = db.Books.Include(b => b.Genre).SingleOrDefault(b => b.bookIdPK == id);

            var rentalPrice    = 0.0;
            var oneMonthRental = 0.0;
            var sixMonthRental = 0.0;

            if (user != null && !User.IsInRole(SD.adminUserRole))
            {
                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes on u.membershipTypeId equals m.membershipTypesIdPK
                                 where u.Id.Equals(userId)
                                 select new
                {
                    m.chargeRateOneMonth,
                    m.chargeRateSixMonth
                };
                oneMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].chargeRateOneMonth) / 100;
                sixMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].chargeRateSixMonth) / 100;
            }
            BookRentalViewModel model = new BookRentalViewModel
            {
                bookId              = bookModel.bookIdPK,
                ISBN                = bookModel.ISBN,
                author              = bookModel.author,
                availability        = bookModel.availability,
                dateAdded           = bookModel.dateAdded,
                description         = bookModel.description,
                Genre               = db.Genres.FirstOrDefault(g => g.genreIdPK.Equals(bookModel.genreId)),
                genreId             = bookModel.genreId,
                imgUrl              = bookModel.imgUrl,
                pages               = bookModel.pages,
                Price               = bookModel.Price,
                publicationDate     = bookModel.publicationDate,
                productDimensions   = bookModel.productDimensions,
                tittle              = bookModel.tittle,
                userRentId          = userId,
                rentalPrice         = rentalPrice,
                rentalPriceOneMonth = oneMonthRental,
                rentalPriceSixMonth = sixMonthRental,
                publisher           = bookModel.publisher
            };

            return(View(model));
        }
Esempio n. 12
0
        public ActionResult Decline(BookRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookRent bookRent = db.BookRental.Find(model.Id);

            bookRent.Status = BookRent.StatusEnum.Rejected;
            Book bookInDb = db.Books.Find(bookRent.BookId);

            bookInDb.Inventory += 1;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
        public ActionResult Approve(BookRentalViewModel model, int?id)
        {
            if (id == 0 || id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookRent bookRent = db.BookRents.Find(id);

            bookRent.Status = BookRent.statusEnum.approved;

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        // GET Method
        public ActionResult Create(string title = null, string ISBN = null)
        {
            if (title != null && ISBN != null)
            {
                BookRentalViewModel model = new BookRentalViewModel()
                {
                    Title = title,
                    ISBN  = ISBN,
                };
                return(View(model));
            }


            return(View(new BookRentalViewModel()));
        }
Esempio n. 15
0
        private BookRentalViewModel getViewModelFromBookRent(BookRent bookRent)
        {
            Book bookSelected = db.Books.Where(b => b.bookIdPK == bookRent.bookRentId).FirstOrDefault();

            var userDetails = from u in db.Users
                              where u.Id.Equals(bookRent.userRentId)
                              select new
            {
                u.Id,
                u.fname,
                u.lname,
                u.bdate,
                u.Email
            };

            BookRentalViewModel model = new BookRentalViewModel()
            {
                userRentId        = bookRent.userRentId,
                bookRentalIdPK    = bookRent.bookRentIdPK,
                bookId            = bookSelected.bookIdPK,
                rentalPrice       = bookRent.rentalPrice,
                Price             = bookSelected.Price,
                pages             = bookSelected.pages,
                fname             = userDetails.ToList()[0].fname,
                lname             = userDetails.ToList()[0].lname,
                bdate             = userDetails.ToList()[0].bdate,
                email             = userDetails.ToList()[0].Email,
                scheduledEndDate  = bookRent.scheduledEndDate,
                rentalDuration    = bookRent.rentalDuration,
                author            = bookSelected.author,
                startDate         = bookRent.startDate,
                availability      = bookSelected.availability,
                description       = bookSelected.description,
                genreId           = bookSelected.genreId,
                Genre             = db.Genres.FirstOrDefault(g => g.genreIdPK.Equals(bookSelected.genreId)),
                ISBN              = bookSelected.ISBN,
                imgUrl            = bookSelected.imgUrl,
                productDimensions = bookSelected.productDimensions,
                publicationDate   = bookSelected.publicationDate,
                publisher         = bookSelected.publisher,
                Status            = bookRent.Status.ToString(),
                tittle            = bookSelected.tittle,
                additionalCharge  = bookRent.additionalCharge
            };

            return(model);
        }
Esempio n. 16
0
        public ActionResult Reserve(BookRentalViewModel book)
        {
            var    userid     = User.Identity.GetUserId();
            Book   bookToRent = db.Books.Find(book.BookId);
            double rentalPr   = 0;

            if (userid != null)
            {
                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes
                                 on u.MembershipTypeId equals m.Id
                                 where u.Id.Equals(userid)
                                 select new { m.ChargeRateOneMonth, m.ChargeRateSixMonth };
                if (book.RentalDuration == SD.SixMonthCount)
                {
                    rentalPr = Convert.ToDouble(bookToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;
                }
                else
                {
                    rentalPr = Convert.ToDouble(bookToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                }
                var userInDb = db.Users.SingleOrDefault(c => c.Id == userid);
                //if (userInDb.RentalCount == 10)
                //{
                //    userInDb.RentalCount++;
                //    rentalPr = rentalPr - (rentalPr * 20 / 100);
                //}
                BookRent bookRent = new BookRent
                {
                    BookId         = bookToRent.Id,
                    UserId         = userid,
                    RentalDuration = book.RentalDuration,
                    RentalPrice    = rentalPr,
                    Status         = BookRent.StatusEnum.Requested,
                };

                db.BookRental.Add(bookRent);
                var bookInDb = db.Books.SingleOrDefault(c => c.Id == book.BookId);

                bookInDb.Avaibility -= 1;

                db.SaveChanges();
                return(RedirectToAction("Index", "BookRent"));
            }
            return(View());
        }
Esempio n. 17
0
 public ActionResult Decline(BookRentalViewModel model)
 {
     if (model.Id == 0)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     if (ModelState.IsValid)
     {
         BookRent bookRent = db.BookRental.Find(model.Id);
         bookRent.Status = BookRent.StatusEnum.Rejected;
         var  userInDb = db.Users.SingleOrDefault(c => c.Id == bookRent.UserId);
         Book bookInDb = db.Books.Find(bookRent.BookId);
         bookInDb.Avaibility += 1;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
        public ActionResult PickUp(BookRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                BookRent bookRent = db.BookRental.Find(model.Id);
                bookRent.Status    = BookRent.StatusEnum.Rented;
                bookRent.StartDate = DateTime.Now;
                if (bookRent.RentalDuration == SD.SixMonthCount)
                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.SixMonthCount));
                }
                if (bookRent.RentalDuration == SD.TwoMonthCount)
                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.TwoMonthCount));
                }
                if (bookRent.RentalDuration == SD.ThreeMonthCount)
                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.ThreeMonthCount));
                }
                if (bookRent.RentalDuration == SD.FourMonthCount)
                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.FourMonthCount));
                }
                if (bookRent.RentalDuration == SD.FiveMonthCount)
                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.FiveMonthCount));
                }
                if (bookRent.RentalDuration == SD.TwoWeeksCount)
                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.OneMonthCount));
                }
                if (bookRent.RentalDuration == SD.OneMonthCount)

                {
                    bookRent.ScheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.OneMonthCount));
                }

                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 19
0
        public ActionResult Return(BookRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                BookRent bookRent = db.BookRental.Find(model.Id);
                bookRent.Status           = BookRent.StatusEnum.Closed;
                bookRent.AdditionalCharge = model.AdditionalCharge;
                Book bookInDb = db.Books.Find(bookRent.BookId);
                bookInDb.Inventory += 1;

                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 20
0
        public ActionResult Reserve(BookRentalViewModel book)
        {
            var    userId      = User.Identity.GetUserId();
            Book   bookToRent  = db.Books.Find(book.bookId);
            double rentalPrice = 0;

            if (userId != null)
            {
                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes on u.membershipTypeId equals m.membershipTypesIdPK
                                 where u.Id.Equals(userId)
                                 select new
                {
                    m.chargeRateOneMonth,
                    m.chargeRateSixMonth
                };

                if (book.rentalDuration == SD.sixMonthCount)
                {
                    rentalPrice = Convert.ToDouble(bookToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].chargeRateSixMonth) / 100;
                }
                else
                {
                    rentalPrice = Convert.ToDouble(bookToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].chargeRateOneMonth) / 100;
                }
                BookRent bookRent = new BookRent
                {
                    bookRentId     = bookToRent.bookIdPK,
                    userRentId     = userId,
                    rentalDuration = book.rentalDuration,
                    rentalPrice    = rentalPrice,
                    Status         = BookRent.statusEnum.Requested
                };

                db.BookRents.Add(bookRent);

                var bookIdDb = db.Books.SingleOrDefault(c => c.bookIdPK == book.bookId);
                bookIdDb.availability -= 1;
                db.SaveChanges();
                return(RedirectToAction("Index", "BookRent"));
            }

            return(View());
        }
Esempio n. 21
0
        public ActionResult Reserve(BookRentalViewModel book)
        {
            var    userid     = User.Identity.GetUserId();
            Book   bookToRent = db.Books.Find(book.BookID);
            double rentalPr   = 0;

            if (userid != null)
            {
                var chargeRate = from u in db.Users
                                 join m in db.Memberships
                                 on u.MembershipID equals m.ID
                                 where u.Id.Equals(userid)
                                 select new { m.ChargeRateSixMonth, m.ChargeRateTwelveMonth };

                if (book.RentalDuration == StaticDetails.TwelveMonthCount)
                {
                    rentalPr = Convert.ToDouble(bookToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateTwelveMonth) / 100;
                }
                else
                {
                    rentalPr = Convert.ToDouble(bookToRent.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;
                }

                BookRental bookRent = new BookRental
                {
                    BookID         = bookToRent.ID,
                    UserID         = userid,
                    RentalDuration = book.RentalDuration,
                    RentalPrice    = rentalPr,
                    Status         = BookRental.StatusEnum.Requested,
                };

                db.BookRentals.Add(bookRent);
                //finds record from the database
                var bookInDb = db.Books.SingleOrDefault(c => c.ID == book.BookID);
                //update availability
                bookInDb.Availability -= 1;
                db.SaveChanges();
                return(RedirectToAction("Index", "BookRental"));
            }

            return(View());
        }
Esempio n. 22
0
        public ActionResult Decline(BookRentalViewModel model, int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookRent bookRent = db.BookRents.Find(id);

            bookRent.Status = BookRent.statusEnum.Rejected;

            Book bookInDB = db.Books.Find(bookRent.bookRentId);

            bookInDB.availability += 1;

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
        //converts bookrent object into a BookRentalViewModel object
        private BookRentalViewModel getVMFromBookRent(BookRental bookRent)
        {
            //retrieves book from the database
            Book bookSelected = db.Books.Where(b => b.ID == bookRent.BookID).FirstOrDefault();

            var userDetails = from u in db.Users
                              where u.Id.Equals(bookRent.UserID)
                              select new { u.Id, u.FirstName, u.LastName, u.BirthDate, u.Email };

            BookRentalViewModel model = new BookRentalViewModel
            {
                ID                  = bookRent.ID,
                BookID              = bookSelected.ID,
                RentalPrice         = bookRent.RentalPrice,
                Price               = bookSelected.Price,
                Pages               = bookSelected.Pages,
                FirstName           = userDetails.ToList()[0].FirstName,
                LastName            = userDetails.ToList()[0].LastName,
                BirthDate           = userDetails.ToList()[0].BirthDate,
                ScheduledReturnDate = bookRent.ScheduledReturnDate,
                Author              = bookSelected.Author,
                StartDate           = bookRent.StartDate,
                Availability        = bookSelected.Availability,
                AdditionalCharge    = bookRent.AdditionalCharge,
                DateAdded           = bookSelected.DateAdded,
                Description         = bookSelected.Description,
                Email               = userDetails.ToList()[0].Email,
                GenreID             = bookSelected.GenreID,
                Genre               = db.Genres.FirstOrDefault(g => g.ID.Equals(bookSelected.GenreID)),
                ISBN                = bookSelected.ISBN,
                ImageUrl            = bookSelected.ImageUrl,
                PublicationDate     = bookSelected.PublicationDate,
                Publisher           = bookSelected.Publisher,
                RentalDuration      = bookRent.RentalDuration,
                Status              = bookRent.Status.ToString(),
                Title               = bookSelected.Title,
                UserID              = userDetails.ToList()[0].Id
            };

            return(model);
        }
Esempio n. 24
0
        private BookRentalViewModel getVM(BookRent bookRent)
        {
            Book bookSelected = db.Books.Where(b => b.Id == bookRent.BookId).FirstOrDefault();

            var userDetails = from u in db.Users
                              where u.Id.Equals(bookRent.UserId)
                              select new { u.Id, u.FirstName, u.LastName, u.BirthDate, u.Email };

            BookRentalViewModel model = new BookRentalViewModel
            {
                Id               = bookRent.Id,
                BookId           = bookSelected.Id,
                RentalPrice      = bookRent.RentalPrice,
                Price            = bookSelected.Price,
                Pages            = bookSelected.Pages,
                FirstName        = userDetails.ToList()[0].FirstName,
                LastName         = userDetails.ToList()[0].LastName,
                BirthDate        = userDetails.ToList()[0].BirthDate,
                Email            = userDetails.ToList()[0].Email,
                UserId           = userDetails.ToList()[0].Id,
                ScheduledEndDate = bookRent.ScheduledEndDate,
                Author           = bookSelected.Author,
                StartDate        = bookRent.StartDate,
                Avaibility       = bookSelected.Avaibility,
                DateAdded        = bookSelected.DateAdded,
                Description      = bookSelected.Description,
                GenreId          = bookSelected.GenreId,
                Genre            = db.Genres.FirstOrDefault(g => g.Id.Equals(bookSelected.GenreId)),
                ISBN             = bookSelected.ISBN,
                ImageUrl         = bookSelected.ImageUrl,
                ProductDimension = bookSelected.ProductDimension,
                PublicationDate  = bookSelected.PublicationDate,
                Publisher        = bookSelected.Publisher,
                RentalDuration   = bookRent.RentalDuration,
                Status           = bookRent.Status.ToString(),
                Title            = bookSelected.Title,
                AdditionalCharge = bookRent.AdditionalCharge
            };

            return(model);
        }
Esempio n. 25
0
        public ActionResult Decline(BookRentalViewModel model)
        {
            if (model.ID == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                BookRental bookRent = db.BookRentals.Find(model.ID);
                bookRent.Status = BookRental.StatusEnum.Rejected;

                //find book from database
                Book bookInDb = db.Books.Find(bookRent.BookID);
                //update the availability
                bookInDb.Availability += 1;
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 26
0
        public ActionResult Return(BookRentalViewModel model)
        {
            if (model.Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookRent bookRent = db.BookRental.Find(model.Id);

            bookRent.Status           = BookRent.StatusEnum.Closed;
            bookRent.AdditionalCharge = model.AdditionalCharge;
            bookRent.ActualEndDate    = DateTime.Now;

            Book bookInDb = db.Books.Find(bookRent.BookId);

            bookInDb.Avaibility += 1;

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 27
0
        public ActionResult Return(BookRentalViewModel model, int?id)
        {
            if (model.bookRentalIdPK == 0 && (id == 0 || id == null))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookRent bookRent = db.BookRents.Find(id);

            bookRent.Status = BookRent.statusEnum.Closed;

            bookRent.additionalCharge = model.additionalCharge;

            Book bookInDB = db.Books.Find(bookRent.bookRentId);

            bookInDB.availability += 1;

            bookRent.actualEndDate = DateTime.Now;

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 28
0
        public ActionResult PickUp(BookRentalViewModel model, int?id)
        {
            if (id == 0 || id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BookRent bookRent = db.BookRents.Find(id);

            bookRent.Status    = BookRent.statusEnum.Rented;
            bookRent.startDate = Convert.ToDateTime(DateTime.Now.ToString("MMM dd yyyy HH:mm"));
            if (bookRent.rentalDuration == SD.sixMonthCount)
            {
                bookRent.scheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.sixMonthCount));
            }
            else
            {
                bookRent.scheduledEndDate = DateTime.Now.AddMonths(Convert.ToInt32(SD.oneMonthCount));
            }

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 29
0
        public ActionResult Return(BookRentalViewModel model)
        {
            if (model.ID == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                BookRental bookRent = db.BookRentals.Find(model.ID);
                bookRent.Status = BookRental.StatusEnum.Closed;
                //allows admin to add additional charge
                bookRent.AdditionalCharge = model.AdditionalCharge;


                Book bookInDb = db.Books.Find(bookRent.BookID);
                //update book availability
                bookInDb.Availability += 1;

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        // GET: BookDetail
        public ActionResult Index(int id)
        {
            var userid = User.Identity.GetUserId();
            var user   = db.Users.FirstOrDefault(u => u.Id == userid);

            var bookModel = db.Books.Include(b => b.Genre).SingleOrDefault(b => b.Id == id);

            //var x = db.Favourites.Where(f => f.UserId == userid && f.bookId == BookId).FirstOrDefault();
            var FavouriteModel = db.Favourites.Where(f => f.UserId == userid && f.bookId == bookModel.Id).FirstOrDefault();

            var rentalPrice      = 0.0;
            var oneMonthRental   = 0.0;
            var sixMonthRental   = 0.0;
            var TwoWeeksRental   = 0.0;
            var TwoMonthRental   = 0.0;
            var ThreeMonthRental = 0.0;
            var FourMonthRental  = 0.0;
            var FiveMonthRental  = 0.0;
            var rentalCount      = 0;

            if (userid != null && !User.IsInRole(SD.AdminUserRole))
            {
                var chargeRate = from u in db.Users
                                 join m in db.MembershipTypes on u.MembershipTypeId equals m.Id
                                 where u.Id.Equals(userid)
                                 select new { m.ChargeRateOneMonth, m.ChargeRateSixMonth,
                                              m.ChargeRateFiveMonth,
                                              m.ChargeRateFourMonth,
                                              m.ChargeRateThreeMonth,
                                              m.ChargeRateTwoMonth,
                                              m.ChargeRateTwoweeks,
                                              u.RentalCount };

                oneMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                sixMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;

                TwoWeeksRental   = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateTwoweeks) / 100;
                TwoMonthRental   = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateTwoMonth) / 100;
                ThreeMonthRental = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateThreeMonth) / 100;
                FourMonthRental  = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateFourMonth) / 100;
                FiveMonthRental  = Convert.ToDouble(bookModel.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateFiveMonth) / 100;



                rentalCount = Convert.ToInt32(chargeRate.ToList()[0].RentalCount);
            }
            BookRentalViewModel model = new BookRentalViewModel
            {
                //UserStatus = usermodel.Disable,
                BookId                = bookModel.Id,
                ISBN                  = bookModel.ISBN,
                Author                = bookModel.Author,
                Avaibility            = bookModel.Avaibility,
                DateAdded             = bookModel.DateAdded,
                Description           = bookModel.Description,
                Genre                 = db.Genres.FirstOrDefault(g => g.Id.Equals(bookModel.GenreId)),
                GenreId               = bookModel.GenreId,
                ImageUrl              = bookModel.ImageUrl,
                Pages                 = bookModel.Pages,
                Price                 = bookModel.Price,
                Publisher             = bookModel.Publisher,
                PublicationDate       = bookModel.PublicationDate,
                ProductDimensions     = bookModel.ProductDimensions,
                Title                 = bookModel.Title,
                UserId                = userid,
                RentalPrice           = rentalPrice,
                RentalPriceOneMonth   = oneMonthRental,
                RentalPriceSixMonth   = sixMonthRental,
                RentalPriceTwoMonth   = TwoMonthRental,
                RentalPriceThreeMonth = ThreeMonthRental,
                RentalPriceFourMonth  = FourMonthRental,
                RentalPriceFiveMonth  = FiveMonthRental,
                RentalPriceTwoWeeks   = TwoWeeksRental,
                RentalCount           = rentalCount,
                //-------------------------
                UserStatus  = (user != null) ? user.Disable:false,
                FavouriteID = (FavouriteModel != null) ? FavouriteModel.id : 0
            };

            return(View(model));
        }