Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook)
        {
            if (id != rentedBook.RentedBookID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentedBook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentedBookExists(rentedBook.RentedBookID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookID"]    = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID);
            ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID);
            return(View(rentedBook));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook)
        {
            Book book = _context.Books.Find(rentedBook.BookID);

            var checkBook = _context.RentedBooks
                            .Include(r => r.Book)
                            .Include(r => r.Student).ToList();

            // if there are more than 1, book will be issued
            if (book.AvailableQuantity >= 1)
            {
                book.AvailableQuantity    -= 1;
                _context.Entry(book).State = EntityState.Modified;

                if (ModelState.IsValid)
                {
                    _context.Add(rentedBook);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            // if none, give a message telling user that the book is current unavailable
            else
            {
                ModelState.AddModelError(string.Empty,
                                         "The book is unavailable! It is rented by other students.");
            }

            ViewData["BookID"]    = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID);
            ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID);
            return(View(rentedBook));
        }
Ejemplo n.º 3
0
 public void Add(RentedBook rentedBook)
 {
     using (context = new LibraryDBContext())
     {
         context.RentedBooks.Add(rentedBook);
         context.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public void Remove(RentedBook rentedBook)
 {
     using (context = new LibraryDBContext())
     {
         RentedBook newRentedBook = context.RentedBooks.FirstOrDefault(x => x.Id == rentedBook.Id);
         context.RentedBooks.Remove(newRentedBook);
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
        public ActionResult Rent([Bind(Include = "Id,BookId,UserId,DateRented,DateToReturn,IsDeleted")] RentedBook rentedBook)
        {
            if (ModelState.IsValid)
            {
                _rentedBookRepo.Create(Mapper.Map <RentedBookBusiness>(rentedBook));
                return(RedirectToAction("Index"));
            }

            return(View(rentedBook));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            RentedBook rentedBook = db.RentedBooks.Find(id);
            Book       book       = db.Books.Find(rentedBook.BookId);

            book.Available = true;

            db.RentedBooks.Remove(rentedBook);
            db.Entry(book).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void ReturnBook(int id, int orderId, decimal price)
        {
            Book book = _context.Books.Find(id);

            book.CountNow += 1;
            _context.SaveChanges();
            RentedBook rentedBook = _context.RentedBooks.Find(orderId);

            rentedBook.isReturn  = true;
            rentedBook.CalcPrice = price;
            _context.SaveChanges();
        }
Ejemplo n.º 8
0
        // GET: Users/Rent/5
        public ActionResult Rent()
        {
            //User user = Mapper.Map<User>(_userRepo.Read(id));
            var rentedBookView = new RentedBook {
                DateRented = DateTime.Now, DateToReturn = DateTime.Now.AddMonths(1)
            };

            ViewBag.BookId = new SelectList(_bookRepo.ReadAll(), "Id", "Name");
            ViewBag.UserId = new SelectList(_userRepo.ReadAll(), "Id", "Name");

            return(View(rentedBookView));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentedBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookID"]    = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID);
            ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID);
            return(View(rentedBook));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentedBook rentedBook = db.RentedBooks.Find(id);

            if (rentedBook == null)
            {
                return(HttpNotFound());
            }
            return(View(rentedBook));
        }
        public ActionResult RentConfirmation(int id)
        {
            Book book = db.Books.Find(id);

            if (book == null)
            {
                return(HttpNotFound());
            }
            var model = new RentedBook();

            model.BookId     = id;
            model.RentDate   = DateTime.Now;
            model.ReturnDate = model.RentDate.AddDays(14);
            model.Penalty    = 0;
            return(View(book));
        }
        public ActionResult <CreateRentedBook> RentBook(CreateRentedBook rentedBook)
        {
            RentedBook rented = _mapper.Map <RentedBook>(rentedBook);

            try
            {
                var test = _repository.RentBook(rented);
                _repository.SaveChanges();
                CreateRentedBook rentBookDto = _mapper.Map <CreateRentedBook>(test);
                return(Ok(rentBookDto));
            }
            catch (KeyNotFoundException e)
            {
                return(NotFound(e.Data["Error"]));
            }
        }
        public ActionResult RentConfirmation([Bind(Include = "RentedBookId,BookId,UserId,RentDate,ReturnDate,Penalty")] RentedBook rentedBook)
        {
            rentedBook.UserName   = User.Identity.GetUserName();
            rentedBook.RentDate   = DateTime.Now;
            rentedBook.ReturnDate = rentedBook.RentDate.AddDays(14);

            Book book = db.Books.Find(rentedBook.BookId);

            book.Available       = false;
            db.Entry(book).State = EntityState.Modified;

            if (ModelState.IsValid)
            {
                db.RentedBooks.Add(rentedBook);
                db.SaveChanges();
                return(RedirectToAction("Index", "Books"));
            }

            return(View(rentedBook));
        }
Ejemplo n.º 14
0
        private void BtnSaveOrder_Click(object sender, RoutedEventArgs e)
        {
            if (customer != null)
            {
                if (selectedBooks.Any())
                {
                    if (MessageBox.Show("Do you want to add this order?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        Order order = new Order();
                        order.CustomerId = customer.Id;
                        order.TakedDate  = DateTime.Today;
                        dr.AddOrder(order);
                        RentedBook rentedBook = new RentedBook();
                        foreach (SelectedBook book in selectedBooks)
                        {
                            rentedBook.BookId     = book.Id;
                            rentedBook.OrderId    = order.Id;
                            rentedBook.ReturnDate = book.ReturnDate;
                            rentedBook.CalcPrice  = book.CalcPrice;
                            rentedBook.Price      = book.Price;
                            dr.RentBook(book.Id);
                            dr.AddRentBook(rentedBook);
                        }
                    }
                    this.Close();
                }


                else
                {
                    MessageBox.Show("You not selected Book!!!");
                }
            }
            else
            {
                MessageBox.Show("You not selected Customer!!!");
            }
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            RentedBook rentedBook = await _context.RentedBooks.FindAsync(id);

            var book = _context.Books.Find(rentedBook.BookID);

            if (book == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            try
            {
                // when a book is returned, book is back to stock => quantity + 1
                book.AvailableQuantity += 1;
                _context.RentedBooks.Remove(rentedBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction(nameof(Delete), new { id = id, saveChangesError = true }));
            }
        }
Ejemplo n.º 16
0
        public RentedBook RentBook(RentedBook rentBook)
        {
            if (_context.Book.FirstOrDefault(b => b.BookId == rentBook.BookId) == null)
            {
                KeyNotFoundException e = new KeyNotFoundException("");
                e.Data["Error"] = new
                {
                    Errors = new
                    {
                        BookId = $"Book with id {rentBook.BookId} could not be found"
                    },
                    Type   = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
                    Status = 404
                };
                throw e;
            }

            if (_context.Users.FirstOrDefault(u => u.UserId == rentBook.UserId) == null)
            {
                KeyNotFoundException e = new KeyNotFoundException("");
                e.Data["Error"] = new
                {
                    Errors = new
                    {
                        BookId = $"User with id {rentBook.UserId} could not be found"
                    },
                    Type   = "https://tools.ietf.org/html/rfc7231#section-6.5.4",
                    Status = 404
                };
                throw e;
            }

            _context.RentedBook.Add(rentBook);
            SaveChanges();
            return(rentBook);
        }
Ejemplo n.º 17
0
 /* Called just after creating this rental */
 private void StartRental()
 {
     RentedBook.BorrowBook();
     AssociatedUser.AddBook();
 }
Ejemplo n.º 18
0
        public static void Initialize(DatabaseContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Books.Any())
            {
                return;   // DB has been seeded
            }

            var books = new Book[]
            {
                new Book {
                    BookName = "The Hiding Place", Author = "Corrie ten Boom", Edition = "35th", ISBN = 9780800794057,
                    Subject  = "Literature", PublicDate = DateTime.Parse("2016-01-01"), Format = "Paperback", NumofPages = 144
                },

                new Book {
                    BookName = "The Common Core Mathematics Companion: The Standards Decoded", Author = " Linda M. Gojak", Edition = "1st", ISBN = 9781483381602,
                    Subject  = "Math", PublicDate = DateTime.Parse("2015-07-05"), Format = "Paperback", NumofPages = 320
                }
            };

            foreach (Book b in books)
            {
                context.Books.Add(b);
            }
            context.SaveChanges();



            var students = new Student[]
            {
                new Student {
                    StudentFirstName = "Thuan", StudentLastName = "Ho", StudentEmail = "*****@*****.**"
                },
                new Student {
                    StudentFirstName = "John", StudentLastName = "Henry", StudentEmail = "*****@*****.**"
                }
            };

            foreach (Student c in students)
            {
                context.Students.Add(c);
            }
            context.SaveChanges();



            var rentedBooks = new RentedBook[]
            {
                new RentedBook {
                    BookID = 2, StudentID = 2, RentDate = DateTime.Now, ReturnDate = DateTime.Parse("2019-10-02")
                },
                new RentedBook {
                    BookID = 1, StudentID = 1, RentDate = DateTime.Now, ReturnDate = DateTime.Parse("2019-09-02")
                }
            };

            foreach (RentedBook r in rentedBooks)
            {
                context.RentedBooks.Add(r);
            }
            context.SaveChanges();
        }
Ejemplo n.º 19
0
        public static void Initialize(LibDbContext context)
        {
            context.Database.EnsureCreated();

            // initial data for BOOK
            if (context.Books.Any())
            {
                return;
            }
            var books = new Book[]
            {
                new Book {
                    BookName = "Book 1", Author = "Author 1", Edition = "1st", ISBN = 111111111, Subject = "Math", PublicDate = DateTime.Parse("2005-09-01"),
                    Format   = "Paperback", NumofPages = 111, AvailableQuantity = 1
                },

                new Book {
                    BookName = "Book 2", Author = "Author 2", Edition = "2nd", ISBN = 222222222, Subject = "Physic", PublicDate = DateTime.Parse("2002-09-01"),
                    Format   = "Paperback", NumofPages = 222, AvailableQuantity = 2
                },

                new Book {
                    BookName = "Book 3", Author = "Author 3", Edition = "3rd", ISBN = 333333333, Subject = "Chemistry", PublicDate = DateTime.Parse("2003-09-01"),
                    Format   = "Paperback", NumofPages = 333, AvailableQuantity = 3
                },

                new Book {
                    BookName = "Book 4", Author = "Author 4", Edition = "4th", ISBN = 444444444, Subject = "Psychology", PublicDate = DateTime.Parse("2005-09-01"),
                    Format   = "Paperback", NumofPages = 444, AvailableQuantity = 4
                },

                new Book {
                    BookName = "Book 5", Author = "Author 5", Edition = "5th", ISBN = 555555555, Subject = "Math", PublicDate = DateTime.Parse("2007-08-02"),
                    Format   = "Paperback", NumofPages = 555, AvailableQuantity = 5
                },

                new Book {
                    BookName = "Book 6", Author = "Author 6", Edition = "6th", ISBN = 666666666, Subject = "Accounting", PublicDate = DateTime.Parse("2010-09-01"),
                    Format   = "Paperback", NumofPages = 666, AvailableQuantity = 6
                },

                new Book {
                    BookName = "Book 7", Author = "Author 7", Edition = "7th", ISBN = 777777777, Subject = "Architecture", PublicDate = DateTime.Parse("2012-09-05"),
                    Format   = "Paperback", NumofPages = 777, AvailableQuantity = 7
                },

                new Book {
                    BookName = "Book 8", Author = "Author 8", Edition = "8th", ISBN = 888888888, Subject = "Film Making", PublicDate = DateTime.Parse("2006-09-01"),
                    Format   = "Paperback", NumofPages = 888, AvailableQuantity = 8
                },
            };

            foreach (Book b in books)
            {
                context.Books.Add(b);
            }
            context.SaveChanges();



            // initial data for STUDENT
            var students = new Student[]
            {
                new Student {
                    StudentFirstName = "First Name 1", StudentLastName = "Last Name 1", StudentEmail = "*****@*****.**", StudentPhoneNumber = "1111111111"
                },

                new Student {
                    StudentFirstName = "First Name 2", StudentLastName = "Last Name 2", StudentEmail = "*****@*****.**", StudentPhoneNumber = "2222222222"
                },

                new Student {
                    StudentFirstName = "First Name 3", StudentLastName = "Last Name 3", StudentEmail = "*****@*****.**", StudentPhoneNumber = "3333333333"
                },

                new Student {
                    StudentFirstName = "First Name 4", StudentLastName = "Last Name 4", StudentEmail = "*****@*****.**", StudentPhoneNumber = "4444444444"
                },

                new Student {
                    StudentFirstName = "First Name 5", StudentLastName = "Last Name 5", StudentEmail = "*****@*****.**", StudentPhoneNumber = "5555555555"
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();



            // initial data for LIST OF RENTED BOOKS
            var rentedbooks = new RentedBook[]
            {
                new RentedBook {
                    StudentID = 1, BookID = 2, RentDate = DateTime.Parse("2019-08-17"), ReturnDate = DateTime.Parse("2019-08-21")
                },

                new RentedBook {
                    StudentID = 1, BookID = 1, RentDate = DateTime.Parse("2019-08-20"), ReturnDate = DateTime.Parse("2019-08-27")
                },

                new RentedBook {
                    StudentID = 3, BookID = 4, RentDate = DateTime.Parse("2019-08-10"), ReturnDate = DateTime.Parse("2019-08-17")
                },

                new RentedBook {
                    StudentID = 2, BookID = 5, RentDate = DateTime.Parse("2019-08-16"), ReturnDate = DateTime.Parse("2019-08-26")
                },
            };

            foreach (RentedBook rb in rentedbooks)
            {
                context.RentedBooks.Add(rb);
            }
            context.SaveChanges();
        }
 public void AddRentBook(RentedBook rentedBook)
 {
     _context.RentedBooks.Add(rentedBook);
     _context.SaveChanges();
 }
        protected override void Seed(Library_Managment.DAL.AppContext context)
        {
            //Books
            Book book1 = new Book
            {
                Name     = "The Lion, the Witch and the Wardrobe",
                Author   = "C. S. Lewis",
                Count    = 8,
                CountNow = 6,
                Price    = 55.5M
            };
            Book book2 = new Book
            {
                Name     = "She: A History of Adventure",
                Author   = "H. Rider Haggard",
                Count    = 4,
                CountNow = 2,
                Price    = 109.8M
            };
            Book book3 = new Book
            {
                Name     = "The Adventures of Pinocchio",
                Author   = "Carlo Collodi",
                Count    = 2,
                CountNow = 1,
                Price    = 87.5M
            };
            Book book4 = new Book
            {
                Name     = "Vardi Wala Gunda",
                Author   = "Ved Prakash Sharma",
                Count    = 12,
                CountNow = 11,
                Price    = 95.0M
            };
            Book book5 = new Book
            {
                Name     = "The Da Vinci Code",
                Author   = "Dan Brown",
                Count    = 23,
                CountNow = 21,
                Price    = 25.8M
            };
            Book book6 = new Book
            {
                Name     = "Harry Potter and the Chamber of Secrets",
                Author   = "J. K. Rowling",
                Count    = 48,
                CountNow = 47,
                Price    = 89.9M
            };
            Book book7 = new Book
            {
                Name     = "Harry Potter and the Prisoner of Azkaban",
                Author   = "J. K. Rowling",
                Count    = 48,
                CountNow = 47,
                Price    = 89.9M
            };
            Book book8 = new Book
            {
                Name     = "The Alchemist",
                Author   = "Paulo Coelho",
                Count    = 9,
                CountNow = 7,
                Price    = 94.7M
            };
            Book book9 = new Book
            {
                Name     = "The Catcher in the Rye",
                Author   = "	J. D. Salinger",
                Count    = 38,
                CountNow = 37,
                Price    = 23.8M
            };
            Book book10 = new Book
            {
                Name     = "Think and Grow Rich",
                Author   = "Napoleon Hill",
                Count    = 81,
                CountNow = 79,
                Price    = 25.2M
            };
            Book book11 = new Book
            {
                Name     = "The Bridges of Madison County",
                Author   = "Robert James Waller",
                Count    = 21,
                CountNow = 20,
                Price    = 17.4M
            };
            Book book12 = new Book
            {
                Name     = "Ben-Hur: A Tale of the Christ",
                Author   = "Lew Wallace",
                Count    = 19,
                CountNow = 18,
                Price    = 38M
            };
            Book book13 = new Book
            {
                Name     = "Harry Potter and the Goblet of Fire",
                Author   = "J. K. Rowling",
                Count    = 48,
                CountNow = 47,
                Price    = 89.9M
            };
            Book book14 = new Book
            {
                Name     = "Harry Potter and the Order of the Phoenix",
                Author   = "J. K. Rowling",
                Count    = 48,
                CountNow = 46,
                Price    = 89.9M
            };
            Book book15 = new Book
            {
                Name     = "Harry Potter and the Half-Blood Prince",
                Author   = "J. K. Rowling",
                Count    = 48,
                CountNow = 47,
                Price    = 89.9M
            };
            Book book16 = new Book
            {
                Name     = "Harry Potter and the Deathly Hallows",
                Author   = "J. K. Rowling",
                Count    = 48,
                CountNow = 47,
                Price    = 89.9M
            };

            context.Books.AddOrUpdate(book1);
            context.Books.AddOrUpdate(book2);
            context.Books.AddOrUpdate(book3);
            context.Books.AddOrUpdate(book4);
            context.Books.AddOrUpdate(book5);
            context.Books.AddOrUpdate(book6);
            context.Books.AddOrUpdate(book7);
            context.Books.AddOrUpdate(book8);
            context.Books.AddOrUpdate(book9);
            context.Books.AddOrUpdate(book10);
            context.Books.AddOrUpdate(book11);
            context.Books.AddOrUpdate(book12);
            context.Books.AddOrUpdate(book13);
            context.Books.AddOrUpdate(book14);
            context.Books.AddOrUpdate(book15);
            context.Books.AddOrUpdate(book16);
            context.SaveChanges();


            //Customers
            Customer cust1 = new Customer
            {
                FullName    = "Memmedli Agasef",
                CreateDate  = DateTime.Today.AddDays(-5),
                PhoneNumber = "+994552995921",
                Address     = "Baku,Nizami,Naxcivaski 72",
            };

            Customer cust2 = new Customer
            {
                FullName    = "Ehmedov Behruz",
                CreateDate  = DateTime.Today.AddDays(-28),
                PhoneNumber = "+994556965575",
                Address     = "Tovuz,Qovlar kendi",
            };
            Customer cust3 = new Customer
            {
                FullName    = "Memmedov Teymur",
                CreateDate  = DateTime.Today.AddDays(-95),
                PhoneNumber = "+994772456372",
                Address     = "Masalli,Hacitepe k",
            };

            Customer cust4 = new Customer
            {
                FullName    = "Veliyev Xudaverdi",
                CreateDate  = DateTime.Today.AddDays(-16),
                PhoneNumber = "+994502993756",
                Address     = "Sumqayit,7 microray",
            };

            Customer cust5 = new Customer
            {
                FullName    = "Isgenderov Aynur",
                CreateDate  = DateTime.Today.AddDays(-51),
                PhoneNumber = "+994709938282",
                Address     = "Gence,Nizami",
            };

            Customer cust6 = new Customer
            {
                FullName    = "Hesenov Ates",
                CreateDate  = DateTime.Today.AddDays(-45),
                PhoneNumber = "+9948922121",
                Address     = "Baki,Binegedi,Eliaga Shix 21",
            };

            Customer cust7 = new Customer
            {
                FullName    = "Baxisov Xamid",
                CreateDate  = DateTime.Today.AddDays(-15),
                PhoneNumber = "+994552913425",
                Address     = "Baki,Sabuncu, Oskar Efendiyev 1a",
            };

            Customer cust8 = new Customer
            {
                FullName    = "Isgenderov Serxan",
                CreateDate  = DateTime.Today.AddDays(-102),
                PhoneNumber = "+9945565353",
                Address     = "Baki,Ehmedli,Nesreddin Tusi 38",
            };


            context.Customers.AddOrUpdate(cust1);
            context.Customers.AddOrUpdate(cust2);
            context.Customers.AddOrUpdate(cust3);
            context.Customers.AddOrUpdate(cust4);
            context.Customers.AddOrUpdate(cust5);
            context.Customers.AddOrUpdate(cust6);
            context.Customers.AddOrUpdate(cust7);
            context.Customers.AddOrUpdate(cust8);

            context.SaveChanges();

            //Administrators
            Administrator admin = new Administrator
            {
                Login       = "******",
                Password    = "******",
                FullName    = "Yolcu Nasib",
                CreateDate  = DateTime.Today.AddDays(-309),
                PhoneNumber = "+9942995922",
                Address     = "Baku,Nizami,Naxcivaski 72",
            };

            context.Administrators.AddOrUpdate(admin);
            context.SaveChanges();



            //orders

            Order order1 = new Order
            {
                CustomerId = cust3.Id,
                TakedDate  = DateTime.Today
            };

            Order order2 = new Order
            {
                CustomerId = cust4.Id,
                TakedDate  = DateTime.Today
            };


            Order order3 = new Order
            {
                CustomerId = cust5.Id,
                TakedDate  = DateTime.Today.AddDays(-58)
            };

            Order order4 = new Order
            {
                CustomerId = cust1.Id,
                TakedDate  = DateTime.Today.AddDays(-158)
            };
            Order order5 = new Order
            {
                CustomerId = cust2.Id,
                TakedDate  = DateTime.Today.AddDays(-88)
            };

            Order order6 = new Order
            {
                CustomerId = cust8.Id,
                TakedDate  = DateTime.Today.AddDays(-8)
            };
            Order order7 = new Order
            {
                CustomerId = cust6.Id,
                TakedDate  = DateTime.Today.AddDays(-24)
            };

            Order order8 = new Order
            {
                CustomerId = cust7.Id,
                TakedDate  = DateTime.Today.AddDays(-32)
            };

            context.Orders.AddOrUpdate(order1);
            context.Orders.AddOrUpdate(order2);
            context.Orders.AddOrUpdate(order3);
            context.Orders.AddOrUpdate(order4);
            context.Orders.AddOrUpdate(order5);
            context.Orders.AddOrUpdate(order6);
            context.Orders.AddOrUpdate(order7);
            context.Orders.AddOrUpdate(order8);
            context.SaveChanges();



            //rented book

            RentedBook rentedBook1 = new RentedBook
            {
                BookId     = book1.Id,
                OrderId    = order1.Id,
                ReturnDate = DateTime.Today.AddDays(10),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(10).Subtract(order1.TakedDate).TotalDays) * (book1.Price / 28),
                Price      = book1.Price
            };
            RentedBook rentedBook2 = new RentedBook
            {
                BookId     = book6.Id,
                OrderId    = order1.Id,
                ReturnDate = DateTime.Today.AddDays(17),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(17).Subtract(order1.TakedDate).TotalDays) * (book6.Price / 28),
                Price      = book6.Price
            };
            RentedBook rentedBook3 = new RentedBook
            {
                BookId     = book2.Id,
                OrderId    = order1.Id,
                ReturnDate = DateTime.Today.AddDays(28),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(28).Subtract(order1.TakedDate).TotalDays) * (book2.Price / 28),
                Price      = book2.Price
            };

            RentedBook rentedBook4 = new RentedBook
            {
                BookId     = book1.Id,
                OrderId    = order2.Id,
                ReturnDate = DateTime.Today.AddDays(4),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(4).Subtract(order2.TakedDate).TotalDays) * (book1.Price / 28),
                Price      = book1.Price
            };
            RentedBook rentedBook5 = new RentedBook
            {
                BookId     = book5.Id,
                OrderId    = order2.Id,
                ReturnDate = DateTime.Today.AddDays(7),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(7).Subtract(order2.TakedDate).TotalDays) * (book5.Price / 28),
                Price      = book5.Price
            };
            RentedBook rentedBook6 = new RentedBook
            {
                BookId     = book9.Id,
                OrderId    = order2.Id,
                ReturnDate = DateTime.Today.AddDays(8),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(8).Subtract(order2.TakedDate).TotalDays) * (book9.Price / 28),
                Price      = book9.Price
            };

            RentedBook rentedBook7 = new RentedBook
            {
                BookId     = book16.Id,
                OrderId    = order3.Id,
                ReturnDate = DateTime.Today.AddDays(-10),
                isReturn   = true,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(-10).Subtract(order3.TakedDate).TotalDays) * (book16.Price / 28),
                Price      = book16.Price
            };
            RentedBook rentedBook8 = new RentedBook
            {
                BookId     = book7.Id,
                OrderId    = order3.Id,
                ReturnDate = DateTime.Today.AddDays(-1),
                isReturn   = true,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(-1).Subtract(order3.TakedDate).TotalDays) * (book7.Price / 28),
                Price      = book7.Price
            };
            RentedBook rentedBook9 = new RentedBook
            {
                BookId     = book3.Id,
                OrderId    = order3.Id,
                ReturnDate = DateTime.Today.AddDays(18),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(18).Subtract(order3.TakedDate).TotalDays) * (book3.Price / 28),
                Price      = book3.Price
            };

            RentedBook rentedBook10 = new RentedBook
            {
                BookId     = book4.Id,
                OrderId    = order4.Id,
                ReturnDate = DateTime.Today.AddDays(1),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(1).Subtract(order4.TakedDate).TotalDays) * (book4.Price / 28),
                Price      = book4.Price
            };
            RentedBook rentedBook11 = new RentedBook
            {
                BookId     = book15.Id,
                OrderId    = order4.Id,
                ReturnDate = DateTime.Today.AddDays(57),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(57).Subtract(order4.TakedDate).TotalDays) * (book15.Price / 28),
                Price      = book15.Price
            };
            RentedBook rentedBook12 = new RentedBook
            {
                BookId     = book11.Id,
                OrderId    = order4.Id,
                ReturnDate = DateTime.Today.AddDays(28),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(28).Subtract(order4.TakedDate).TotalDays) * (book11.Price / 28),
                Price      = book11.Price
            };

            RentedBook rentedBook13 = new RentedBook
            {
                BookId     = book8.Id,
                OrderId    = order4.Id,
                ReturnDate = DateTime.Today.AddDays(-1),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(-1).Subtract(order4.TakedDate).TotalDays) * (book8.Price / 28),
                Price      = book8.Price
            };
            RentedBook rentedBook14 = new RentedBook
            {
                BookId     = book8.Id,
                OrderId    = order5.Id,
                ReturnDate = DateTime.Today.AddDays(17),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(17).Subtract(order5.TakedDate).TotalDays) * (book8.Price / 28),
                Price      = book8.Price
            };
            RentedBook rentedBook15 = new RentedBook
            {
                BookId     = book14.Id,
                OrderId    = order5.Id,
                ReturnDate = DateTime.Today.AddDays(8),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(8).Subtract(order5.TakedDate).TotalDays) * (book14.Price / 28),
                Price      = book14.Price
            };

            RentedBook rentedBook16 = new RentedBook
            {
                BookId     = book13.Id,
                OrderId    = order6.Id,
                ReturnDate = DateTime.Today.AddDays(2),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(2).Subtract(order6.TakedDate).TotalDays) * (book13.Price / 28),
                Price      = book13.Price
            };
            RentedBook rentedBook17 = new RentedBook
            {
                BookId     = book10.Id,
                OrderId    = order7.Id,
                ReturnDate = DateTime.Today,
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.Subtract(order7.TakedDate).TotalDays) * (book10.Price / 28),
                Price      = book10.Price
            };
            RentedBook rentedBook18 = new RentedBook
            {
                BookId     = book10.Id,
                OrderId    = order7.Id,
                ReturnDate = DateTime.Today.AddDays(18),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(18).Subtract(order7.TakedDate).TotalDays) * (book10.Price / 28),
                Price      = book10.Price
            };


            RentedBook rentedBook19 = new RentedBook
            {
                BookId     = book2.Id,
                OrderId    = order8.Id,
                ReturnDate = DateTime.Today.AddDays(18),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(18).Subtract(order8.TakedDate).TotalDays) * (book2.Price / 28),
                Price      = book2.Price
            };

            RentedBook rentedBook20 = new RentedBook
            {
                BookId     = book12.Id,
                OrderId    = order8.Id,
                ReturnDate = DateTime.Today.AddDays(-2),
                isReturn   = true,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(-2).Subtract(order8.TakedDate).TotalDays) * (book12.Price / 28),
                Price      = book12.Price
            };
            RentedBook rentedBook21 = new RentedBook
            {
                BookId     = book14.Id,
                OrderId    = order8.Id,
                ReturnDate = DateTime.Today.AddDays(-4),
                isReturn   = true,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(-4).Subtract(order8.TakedDate).TotalDays) * (book14.Price / 28),
                Price      = book14.Price
            };
            RentedBook rentedBook22 = new RentedBook
            {
                BookId     = book5.Id,
                OrderId    = order8.Id,
                ReturnDate = DateTime.Today.AddDays(18),
                isReturn   = false,
                CalcPrice  = Convert.ToDecimal(DateTime.Today.AddDays(18).Subtract(order8.TakedDate).TotalDays) * (book5.Price / 28),
                Price      = book5.Price
            };

            context.RentedBooks.AddOrUpdate(rentedBook1);
            context.RentedBooks.AddOrUpdate(rentedBook2);
            context.RentedBooks.AddOrUpdate(rentedBook3);
            context.RentedBooks.AddOrUpdate(rentedBook4);
            context.RentedBooks.AddOrUpdate(rentedBook5);
            context.RentedBooks.AddOrUpdate(rentedBook6);
            context.RentedBooks.AddOrUpdate(rentedBook7);
            context.RentedBooks.AddOrUpdate(rentedBook8);
            context.RentedBooks.AddOrUpdate(rentedBook9);
            context.RentedBooks.AddOrUpdate(rentedBook10);
            context.RentedBooks.AddOrUpdate(rentedBook11);
            context.RentedBooks.AddOrUpdate(rentedBook12);
            context.RentedBooks.AddOrUpdate(rentedBook13);
            context.RentedBooks.AddOrUpdate(rentedBook14);
            context.RentedBooks.AddOrUpdate(rentedBook15);
            context.RentedBooks.AddOrUpdate(rentedBook16);
            context.RentedBooks.AddOrUpdate(rentedBook17);
            context.RentedBooks.AddOrUpdate(rentedBook18);
            context.RentedBooks.AddOrUpdate(rentedBook19);
            context.RentedBooks.AddOrUpdate(rentedBook20);
            context.RentedBooks.AddOrUpdate(rentedBook21);
            context.RentedBooks.AddOrUpdate(rentedBook22);
            context.SaveChanges();
        }
Ejemplo n.º 22
0
 /* Called just before removing this rental from the list */
 public void EndRental()
 {
     RentedBook.ReturnBook();
     AssociatedUser.RemoveBook();
 }