Ejemplo n.º 1
0
        public ActionResult RentBooks(RentBooksModel model)
        {
            Rented NewRented = new Rented();

            using (var d = new UserContext())
            {
                NewRented.UserProfile = d.UserProfiles.Find((int)WebSecurity.CurrentUserId);
                NewRented.Book        = d.Books.Find(model.NewRented.BookKey);
                NewRented.returned    = true;
                Rented comp = d.Rented.Where(x => x.UserProfile.UserId == (int)WebSecurity.CurrentUserId)
                              .Where(x => x.Book.BookKey == model.NewRented.BookKey)
                              .FirstOrDefault();
                if (comp == null)
                {
                    NewRented.returned = false;
                    d.Rented.Add(NewRented);
                }
                else
                {
                    comp.returned = false;
                }
                d.SaveChanges();
                addHistory(NewRented.UserProfile, NewRented.Book, (States)1);
            }
            return(RentBooks());
        }
Ejemplo n.º 2
0
        // Rent page called to render
        public ActionResult RentBooks()
        {
            List <Rented> rented = null;
            List <Books>  books  = null;

            using (var d = new UserContext())
            {
                rented = d.Rented.AsEnumerable().ToList();
                books  = d.Books.AsEnumerable().ToList();
                RentBooksModel model = new RentBooksModel();
                model.AllRented = rented;
                model.AllBooks  = books;
                return(View(model));
            }
        }