Example #1
0
        // GET: Authors
        public ActionResult Index(int?id, int?bookId, string sortOrder, string searchString, string currentFilter, int pageSize = 10, int pageNumber = 1)
        {
            if (searchString == null)
            {
                searchString = currentFilter;
            }
            else
            {
                pageNumber = 1;
            }

            var model = DependencyResolver.Current.GetService <AuthorIndexViewModel>();

            //var model = new AuthorIndexViewModel();

            _parameterBuilder.Build(model, searchString: searchString, sortingParam: sortOrder, pageSize: pageSize, pageNumber: pageNumber);
            model.Authors = _services.GetAll(model.Sorting, model.Filtering, model.Paging, model.Options);

            if (id != null)
            {
                model.Id    = id.Value;
                model.Books = _bookServices.GetBooksByAuthor(model.Id);
            }

            if (bookId != null)
            {
                ViewBag.BookId = bookId;
            }

            ViewBag.LastNameSort  = String.IsNullOrEmpty(sortOrder) ? "lName_desc" : "";
            ViewBag.FirstNameSort = sortOrder == "fName" ? "fName_desc" : "fName";


            return(View(model));
        }
Example #2
0
        public ActionResult Index(string sortOrder,
                                  string searchString, string currentFilter,
                                  bool showRentalHistory = false,
                                  int pageNumber         = 1, int pageSize = 10, int id = 0)
        {
            if (searchString == null)
            {
                searchString = currentFilter;
            }


            var model = DependencyResolver.Current.GetService <CustomerIndexViewModel>();

            //IEnumerable<IRental> rentals;

            _parameterBuilder.Build(model, searchString: searchString, sortingParam: sortOrder,
                                    pageSize: pageSize, pageNumber: pageNumber,
                                    id: id, IncludeRentalHistory: showRentalHistory);

            IEnumerable <IRental> rentals;

            model.Customers = _customerServices.GetAll(out rentals, model.Sorting, model.Filtering, model.Paging, model.Options);
            model.Rentals   = rentals;

            ViewBag.LastNameSort      = String.IsNullOrEmpty(sortOrder) ? "lName_desc" : "";
            ViewBag.FirstNameSort     = sortOrder == "fName" ? "fName_desc" : "fName";
            ViewBag.AccountNumberSort = sortOrder == "accountNo" ? "accountNo_desc" : "accountNo";

            ViewBag.PageSelectList = new SelectList(new List <int> {
                5, 10, 20, 40
            }, model.Customers.PageSize);

            return(View(model));
        }
        public ActionResult Index(string sortOrder, string searchString, string currentFilter, int id = 0, int pageNumber = 1, int pageSize = 10)
        {
            if (searchString != null)
            {
                pageNumber = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            var model = DependencyResolver.Current.GetService <BookIndexViewModel>();

            _parameterBuilder.Build(model, searchString: searchString, sortingParam: sortOrder, pageSize: pageSize, pageNumber: pageNumber, includeAuthors: true, includeGenres: true);

            model.Books = _services.GetBooksWithAuthorsAndGenres(model.Sorting, model.Filtering, model.Paging, model.Options);

            model.Id = id > 0 ? id : 0;

            ViewBag.TitleSortParam   = String.IsNullOrEmpty(sortOrder) ? "title_desc" : "";
            ViewBag.AuthorSortParam  = sortOrder == "Author" ? "author_desc" : "Author";
            ViewBag.GenreSortParam   = sortOrder == "Genre" ? "genre_desc" : "Genre";
            ViewBag.PageSizeDropdown = new SelectList(new List <int>()
            {
                5, 10, 20, 40
            }, model.Paging.PageNumber);

            return(View(model));
        }
        public ActionResult Index(string sortOrder,
                                  string searchString, string currentFilter, string searchBy,
                                  string recordsFilter,
                                  int pageNumber = 1, int pageSize = 10, int id = 0)
        {
            var model = DependencyResolver.Current.GetService <RentalsIndexViewModel>();

            _parameterBuilder.Build(model, searchString: searchString, searchBy: searchBy, recordsFilter: recordsFilter, sortingParam: sortOrder,
                                    pageSize: pageSize, pageNumber: pageNumber, id: id, IncludeBooks: true, IncludeCustomers: true);

            model.Rentals = _rentalServices.GetAll(model.Sorting, model.Filtering, model.Paging, model.Options);

            if (id > 0)
            {
                model.Rental = Mapper.Map <RentalDTO>(_rentalServices.Get(id));
                if (model.Rental == null)
                {
                    return(HttpNotFound());
                }

                TempData["model"] = model;

                return(RedirectToAction("ReturnBook"));
            }

            ViewBag.DateRentedSort   = String.IsNullOrEmpty(sortOrder) ? "dRented" : "";
            ViewBag.DateReturnedSort = sortOrder == "dReturned" ? "dReturned_desc" : "dReturned";
            ViewBag.BookTitleSort    = sortOrder == "bookTitle" ? "bookTitle_desc" : "bookTitle";
            ViewBag.CustomerNameSort = sortOrder == "customerName" ? "customerName_desc" : "customerName";

            PopulateViewBagDropDowns(model.Filtering.RecordsFilter, model.Filtering.SearchBy, model.Rentals.PageSize);


            return(View(model));
        }
Example #5
0
        private DbCommand CreateCommand()
        {
            if (text is null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            DbCommand command = connection.CreateCommand();

            command.CommandText = text;

            if (!(parameters is null))
            {
                foreach (DbParameter parameter in parameterBuilder.Build(parameters))
                {
                    command.Parameters.Add(parameter);
                }
            }

            return(command);
        }