// GET: Book
        public ActionResult Index()
        {
            //var books = _bookRepository.GetAll();

            //var model = books.Select(b => new BookIndexViewModel()
            //{
            //    Id = b.Id,
            //    ISBN = b.ISBN,
            //    Title = b.Title,
            //    Author = b.Author.FirstName + " " + b.Author.LastName
            //});

            var model = _bookRepository.AsQueryable()
                        .Select(b => new BookIndexViewModel()
            {
                Id     = b.Id,
                ISBN   = b.ISBN,
                Title  = b.Title,
                Author = b.Author.FirstName + " " + b.Author.LastName
            }).ToList();

            return(View(model));
        }
示例#2
0
        // GET: Customer
        public ActionResult Index()
        {
            var model = _CustomerRepository.AsQueryable().ToList()
                        .Select(c => new CustomerIndexViewModel()
            {
                Id          = c.Id,
                UserName    = c.CustomerCode,
                FullName    = c.FirstName + " " + c.MiddleName + " " + c.LastName,
                DateOfBirth = c.DateOfBirth,
                FullAddress = c.StreetAddress + " " + c.Suburb + " " + c.PostCode + " " + c.State
            });

            return(View(model));
        }
        // GET: Product
        public ActionResult Index()
        {
            var model = _ProductRepository.AsQueryable()//add to repository first
                        .Select(p => new ProductIndexViewModel()
            {
                ProductId    = p.Id,
                CategoryName = p.Category.Description,
                ProductName  = p.ProductName,
                Description  = p.Description,
                Price        = p.Price.Value,
                VendorName   = p.Vendor.Name
            });

            //var products = db.Products.Include(p => p.Category).Include(p => p.Vendor);
            return(View(model.ToList()));
        }