コード例 #1
0
        public BookModel BookRent(Client client, BookModel book)
        {
            BackgroundJob.Schedule(() => SendMessage.SendSimpleMessage(_options), TimeSpan.FromSeconds(28));

            client._Id = ObjectId.GenerateNewId();
            Task.Run(() => _clientRepository.Create(client));

            try
            {
                var copy = book.BookCopyItems.FirstOrDefault(c => c.IsAvailable);
                copy.IsAvailable = false;
                var bookRent = new BookRent
                {
                    RentDate          = System.DateTime.Now,
                    AssumedReturnDate = System.DateTime.Now.AddDays(30),
                    Client_Id         = client._Id
                };
                copy.BookRent.Add(bookRent);

                _repository.Update(book);

                return(book);
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }
コード例 #2
0
        public async Task <BookRent> Add(BookRent bookRent)
        {
            db.BookRents.Add(bookRent);
            await db.SaveChangesAsync();

            return(bookRent);
        }
コード例 #3
0
        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"));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("BookRentId,RentDate,Qty,StudentId,BookId")] BookRent bookRent)
        {
            if (id != bookRent.BookRentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bookRent);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookRentExists(bookRent.BookRentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]    = new SelectList(_context.Books, "BookId", "BookId", bookRent.BookId);
            ViewData["StudentId"] = new SelectList(_context.Students, "StudentId", "StudentId", bookRent.StudentId);
            return(View(bookRent));
        }
コード例 #6
0
        public IHttpActionResult rentABook([FromBody] BookRent rentedBook)
        {
            BookRepository cc = new BookRepository();

            cc.rentABook(rentedBook.bookId, rentedBook.userId);
            return(Ok());
        }
        public ActionResult DeleteConfirmed(int Id)
        {
            if (Id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                BookRent bookRent = db.BookRental.Find(Id);
                db.BookRental.Remove(bookRent);

                var bookInDb = db.Books.Where(b => b.Id.Equals(bookRent.BookId)).FirstOrDefault();
                var userInDb = db.Users.SingleOrDefault(c => c.Id == bookRent.UserId);

                if (bookRent.Status.ToString().ToLower().Equals("rented"))
                {
                    bookInDb.Avaibility += 1;
                }
                else
                {
                    //This else would be called in all scenarios except when user has a book with them and never returns
                    if (userInDb.RentalCount == 11)
                    {
                        userInDb.RentalCount--;
                    }
                }
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
コード例 #8
0
        public async Task <BookRent> Edit(BookRent bookRent)
        {
            db.BookRents.Update(bookRent);
            await db.SaveChangesAsync();

            return(bookRent);
        }
コード例 #9
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());
        }
コード例 #10
0
        public ActionResult Create(BookRentViewModel bookRentVM)
        {
            if (ModelState.IsValid)
            {
                var email = bookRentVM.Email;
                var book  = db.Books.Where(b => b.ISBN.Equals(bookRentVM.ISBN)).SingleOrDefault();

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

                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 rentalPrice = 0.0;

                if (bookRentVM.RentalDuration.Equals(SD.OneMonthValue))
                {
                    rentalPrice = Convert.ToDouble(book.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                }

                if (bookRentVM.RentalDuration.Equals(SD.SixMonthValue))
                {
                    rentalPrice = Convert.ToDouble(book.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;
                }

                BookRent bookRentToAddToDb = new BookRent
                {
                    UserId           = userDetails.ToList()[0].Id,
                    BookId           = book.Id,
                    RentalDuration   = bookRentVM.RentalDuration,
                    RentalPrice      = rentalPrice,
                    Status           = BookRent.StatusEnum.Approved,
                    StartDate        = bookRentVM.StartDate,
                    ActualEndDate    = bookRentVM.ActualEndDate,
                    AdditionalCharge = bookRentVM.AdditionalCharge,
                    ScheduledEndDate = bookRentVM.ScheduledEndDate
                };

                db.BookRents.Add(bookRentToAddToDb);
                book.Availibility -= 1;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bookRentVM));
        }
コード例 #11
0
        public void AddBookForUser(string userId, int bookId)
        {
            var bookRent = new BookRent();

            bookRent.BookId = bookId;
            bookRent.UserId = userId;
            applicationDbContext.Add(bookRent);
            applicationDbContext.SaveChanges();
        }
コード例 #12
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());
        }
コード例 #13
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());
        }
コード例 #14
0
        public void CannotRemoveReaderWithBorrowedBook()
        {
            Reader    reader = new Reader("Artur", "Xinski", 123456987);
            BookEvent rent   = new BookRent(
                reader,
                new BookState(new Book("111-222-333", "Wojciech Sowa", "Life is life", "Amazing book"), true, DateTime.Now));

            dataRepository.AddReader(reader);
            dataRepository.AddEvent(rent);

            Assert.ThrowsException <InvalidOperationException>(() => dataRepository.DeleteReader(dataContext.ReadersList.Count - 1));
        }
コード例 #15
0
        static void Main(string[] args)
        {
            var book = new Book()
            {
                Title = "Book 1"
            };
            var bookRent = new BookRent();
            var library  = new Library();

            bookRent.BookRented += library.OnBookRent;

            bookRent.RentBook(book);
        }
コード例 #16
0
        public bool EditBookRent(BookRent bookRentToEdit)
        {
            var editedBookRent = _libraryContext.BookRents.FirstOrDefault(x => x.BookRentId == bookRentToEdit.BookRentId);

            if (editedBookRent == null)
            {
                return(false);
            }
            editedBookRent.DateOfRent   = bookRentToEdit.DateOfRent;
            editedBookRent.DateOfReturn = bookRentToEdit.DateOfReturn;
            _libraryContext.SaveChanges();
            return(true);
        }
コード例 #17
0
        private BookRentViewModel getVMFromBookRent(BookRent bookRent)
        {
            var userDetails = from u in db.Users
                              where u.Id.Equals(bookRent.UserId)
                              select new
            {
                u.FirstName,
                u.LastName,
                u.Email,
                u.Birthday,
                u.Phone,
                u.MembershipTypeId,
            };

            var book = db.Books.Find(bookRent.BookId);


            var model = new BookRentViewModel
            {
                Id               = bookRent.Id,
                UserId           = bookRent.UserId,
                BookId           = bookRent.BookId,
                StartDate        = bookRent.StartDate,
                ActualEndDate    = bookRent.ActualEndDate,
                ScheduledEndDate = bookRent.ScheduledEndDate,
                AdditionalCharge = bookRent.AdditionalCharge,
                RentalPrice      = bookRent.RentalPrice,
                RentalDuration   = bookRent.RentalDuration,
                Pages            = book.Pages,
                Price            = book.Price,
                Status           = bookRent.Status.ToString(),
                FirstName        = userDetails.ToList()[0].FirstName,
                LastName         = userDetails.ToList()[0].LastName,
                Email            = userDetails.ToList()[0].Email,
                Birthday         = userDetails.ToList()[0].Birthday,
                Phone            = userDetails.ToList()[0].Phone,
                Author           = book.Author,
                Availibility     = book.Availibility,
                Description      = book.Description,
                GenreId          = book.GenreId,
                DateAdded        = book.DateAdded,
                ImageUrl         = book.ImageUrl,
                ISBN             = book.ISBN,
                PublicationDate  = book.PublicationDate,
                Title            = book.Title,
                Genre            = db.Genres.FirstOrDefault(g => g.Id == book.GenreId)
            };

            return(model);
        }
コード例 #18
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"));
 }
コード例 #19
0
        public ActionResult Reserve(BookRentViewModel bookRentVM)
        {
            string userId = User.Identity.GetUserId();
            var    user   = db.Users.Find(userId);

            if (user != null)
            {
                var book = db.Books.Find(bookRentVM.BookId);

                var rentalPrice = 0.0;

                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 (bookRentVM.RentalDuration.Equals(SD.OneMonthValue))
                {
                    rentalPrice = Convert.ToDouble(book.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateOneMonth) / 100;
                }
                else
                {
                    rentalPrice = Convert.ToDouble(book.Price) * Convert.ToDouble(chargeRate.ToList()[0].ChargeRateSixMonth) / 100;
                }

                var bookRentToAddToDb = new BookRent
                {
                    UserId           = userId,
                    BookId           = book.Id,
                    ActualEndDate    = bookRentVM.ActualEndDate,
                    StartDate        = bookRentVM.StartDate,
                    AdditionalCharge = bookRentVM.AdditionalCharge,
                    RentalDuration   = bookRentVM.RentalDuration,
                    RentalPrice      = rentalPrice,
                    ScheduledEndDate = bookRentVM.ScheduledEndDate,
                    Status           = BookRent.StatusEnum.Requested
                };

                book.Availibility -= 1;
                db.BookRents.Add(bookRentToAddToDb);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(bookRentVM));
        }
コード例 #20
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"));
        }
コード例 #21
0
        //Return Get Method
        public ActionResult Return(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookRent bookRent = db.BookRental.Find(id);
            var      model    = getVMFromBookRent(bookRent);

            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View("Approve", model));
        }
コード例 #22
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"));
        }
コード例 #23
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BookRent = await _context.BookRent.FirstOrDefaultAsync(m => m.Id == id);

            if (BookRent == null)
            {
                return(NotFound());
            }
            return(Page());
        }
コード例 #24
0
        public async Task <IActionResult> Create(BookRent bookRent)
        {
            if (ModelState.IsValid)
            {
                var book = _context.Books.Find(bookRent.BookId);
                book.Qty -= bookRent.Qty;
                _context.Entry(book).State = EntityState.Modified;
                _context.Add(bookRent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]    = new SelectList(_context.Books, "BookId", "BookId", bookRent.BookId);
            ViewData["StudentId"] = new SelectList(_context.Students, "StudentId", "StudentId", bookRent.StudentId);
            return(View(bookRent));
        }
コード例 #25
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);
        }
コード例 #26
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"));
 }
コード例 #27
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BookRent = await _context.BookRent.FindAsync(id);

            if (BookRent != null)
            {
                _context.BookRent.Remove(BookRent);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #28
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());
        }
コード例 #29
0
        //Save Event
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMemberCode.Text.Trim() == "" || txtDays.Text.Trim() == "" || dgvBookList.Rows.Count == 0)
                {
                    MessageBox.Show("Please fill complete records", "Incomplete Records");
                }
                else
                {
                    DetailBookDT = new DataTable();
                    DetailBookDT.Columns.Add("BookID");

                    for (int i = 0; i < dgvBookList.Rows.Count; i++)
                    {
                        if (dgvBookList.Rows[i].Cells[1].Value == null)
                        {
                            break;
                        }
                        DataRow dr = DetailBookDT.NewRow();
                        dr["BookID"] = dgvBookList.Rows[i].Cells[0].Value.ToString();
                        DetailBookDT.Rows.Add(dr);
                    }

                    if (btnSave.Text.Contains("Save"))
                    {
                        BookRent rentObj = new BookRent();
                        rentObj.MemberId    = Memberobj.MemberID;
                        rentObj.StartDate   = dtpFromDate.Value;
                        rentObj.IssueDate   = dtpToDate.Value;
                        rentObj.NumberOfDay = Convert.ToInt32(txtDays.Text.Trim());

                        int l_return = Rent_DAO.SaveDAO(rentObj, DetailBookDT);
                        if (l_return > 0)
                        {
                            MessageBox.Show("Save Successfully", "Save");
                            Clear();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        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"));
        }