public ActionResult Index(CustomerIndexVM model) { model.PageNumber = CustomerService.ValidatePageNumber(model.PageNumber); model.RowsPerPage = CustomerService.ValidateRowsPerPage(model.RowsPerPage); model.NumberOfPages = CustomerService.GetNumberOfPages(model.RowsPerPage); model.Customers = CustomerService.GetAllOnPage(model.PageNumber, model.RowsPerPage); return(View("Index", model)); }
public ActionResult Search(CustomerIndexVM customerIndexVM) { return(RedirectToAction("Index", "Customer", new { SearchName = customerIndexVM.SearchName })); //CustomerSearchVM customerSearchVM = _mapper.Map<CustomerSearchVM>(customer); //return View(customerSearchVM); }
// GET: Customer public ActionResult Index() { List <Customer> customers = db.Customers.ToList(); CustomerIndexVM vm = new CustomerIndexVM() { Customers = mapper.Map <List <CustomerIndexItemVM> >(customers) }; return(View("Index", vm)); }
public ActionResult Index(Guid?selectedCustomerId, string selectedCountry = null, int page = 0, int rowsPerPage = 5) { int count = _db.Customers.Count(); List <Customer> customers = _db.Customers .Where(x => selectedCountry == null || x.Country == selectedCountry) .Include(c => c.Accounts) .Skip(page * rowsPerPage) .Take(rowsPerPage) .ToList(); Customer selectedCustomer = null; if (selectedCustomerId != null) { selectedCustomer = _db.Customers.FirstOrDefault(x => x.Id == selectedCustomerId); } //// row grouping //List<IGrouping<string, Account>> accountsGroup = _db.Accounts.GroupBy(x => x.Currency).ToList(); //foreach (var group in accountsGroup) //{ // var curency = group.Key; // foreach (var account in group) // { // // listing the accounts in each currency // } //} //// aggregate grouping //Dictionary<string, int> countByCurrency = _db.Accounts // .GroupBy(x => x.Currency) // .ToDictionary(x => x.Key, x => x.Count()); var vm = new CustomerIndexVM { CustomersPageList = new PagedList <Customer> { Page = page, RowsPerPage = rowsPerPage, TotalCount = count, Data = customers }, SelectedCustomer = selectedCustomer, SelectedCountry = selectedCountry, AllCountries = Countries.GetCountries() }; return(View(vm)); }
// GET: CustomerController public ActionResult Index(string searchName = null) { // loads the index page for customer var customers = string.IsNullOrWhiteSpace(searchName)?_customerBL.GetCustomers(): _customerBL.GetCustomersByName(searchName); //else after colon // if you have a searchname, call getcustomersbyname...if you dont then get all the customers var customerVMs = new List <CustomerVM>(); foreach (var item in customers) { var customerVM = _mapper.Map <CustomerVM>(item); customerVMs.Add(customerVM); } var customerIndexVM = new CustomerIndexVM(); customerIndexVM.Customers = customerVMs; return(View(customerIndexVM)); }
// GET: Customers //public async Task<ActionResult> Index(string sortOrder, string searchString, string currentFilter, int? page, int? pageSize) public async Task <ActionResult> Index(CustomerIndexVM customerIndexVM) { // The null-coalescing operator defines a default value for a nullable type; // the expression (page ?? 1) means return the value of page if it has a value // or 1 if page is null. int pSize = (customerIndexVM.PageSize ?? DefaultPageSize); int pNumber = (customerIndexVM.Page ?? 1); // ASP.NET Session State Overview // https://msdn.microsoft.com/en-us/library/ms178581.aspx string firstName = "Jeff"; string lastName = "Smith"; string city = "Seattle"; // Save session variables //Session["FirstName"] = firstName; //Session["LastName"] = lastName; //Session["City"] = city; // Read session variables //firstName = (string)(Session["First"]); //lastName = (string)(Session["Last"]); //city = (string)(Session["City"]); //if (city == null) // No such value in session state; take appropriate action. // When retrieving an object from session state, cast it to // the appropriate type. //ArrayList stockPicks = (ArrayList)Session["StockPicks"]; // Write the modified stock picks list back to session state. //Session["StockPicks"] = stockPicks; // Provide the view with the current sort order. //customerIndexVM.CurrentSort = customerIndexVM.SortOrder ?? ""; customerIndexVM.SortOrder = customerIndexVM.SortOrder ?? ""; // toggle sort params for links in view. if (String.IsNullOrEmpty(customerIndexVM.SortOrder)) { customerIndexVM.CompanyNameSortParm = "company_name_desc"; } else { customerIndexVM.CompanyNameSortParm = customerIndexVM.SortOrder == "company_name" ? "company_name_desc" : "company_name"; } customerIndexVM.ContactNameSortParm = customerIndexVM.SortOrder == "contact_name" ? "contact_name_desc" : "contact_name"; // If the search string is changed during paging, the page has to be reset to 1, // because the new filter can result in different data to display. // The search string is changed when a value is entered in the text box and // the submit button is pressed. In that case, the searchString parameter is not null. if (!String.IsNullOrEmpty(customerIndexVM.SearchString)) { customerIndexVM.Page = 1; } else { customerIndexVM.SearchString = customerIndexVM.CurrentFilter; } // Provide the view with the current filter string. This value must be included // in the paging links in order to maintain the filter settings during paging, // and it must be restored to the textbox when the page is redisplayed. customerIndexVM.CurrentFilter = customerIndexVM.SearchString; customerIndexVM.Page = pNumber; customerIndexVM.PageSize = pSize; // var courses = _unitOfWork.CourseRepository.Get(includeProperties: "Department"); //var customers = _unitOfWork.CustomerRepository.Get(); var customers = from c in _context.Customers orderby c.CompanyName select c; if (!String.IsNullOrEmpty(customerIndexVM.SearchString)) { customers = customers .Where(c => c.CompanyName.Contains(customerIndexVM.SearchString)) .OrderBy(c => c.CompanyName); } switch (customerIndexVM.SortOrder) { case "company_name_desc": customers = customers.OrderByDescending(s => s.CompanyName); break; case "contact_name": customers = customers.OrderBy(s => s.ContactName); break; case "contact_name_desc": customers = customers.OrderByDescending(s => s.ContactName); break; default: customers = customers.OrderBy(s => s.CompanyName); break; } //return View(await db.Customers.ToListAsync()); //return View(await customers.ToPagedListAsync(pNumber, pSize)); customerIndexVM.CustomerPagedList = await customers.ToPagedListAsync(pNumber, pSize); return(View(customerIndexVM)); }