コード例 #1
0
        //// GET: Locations
        //public ActionResult Index()
        //{
        //    return View(db.Locations.ToList());
        //}

        // GET: Locations with search string
        public ActionResult Index(string searchString)
        {
            try
            {
                IEnumerable<Location> locations = new List<Location>();
                if (!String.IsNullOrEmpty(searchString))
                {
                    if (Int32.TryParse(searchString, out int searchInt))
                    {
                        locations = db.Locations.Where(x => x.LocationId.Equals(searchInt));
                    }
                    else
                    {
                        locations = db.Locations
                        .Where(x => x.Name.Contains(searchString));
                    }
                }
                else
                {
                    locations = db.Locations;
                }

                return View(locations.ToList());
            }
            catch (Exception ex)
            {
                ViewBag.errorMessage = (DebuggingUtilities.GetExceptionString(ex));
                return View("../Home/Index");
            }
        }
コード例 #2
0
        //// GET: CheckoutHistories
        //public ActionResult Index()
        //{
        //    var checkoutHistories = db.CheckoutHistories.Include(c => c.Asset).Include(c => c.Patron);
        //    return View(checkoutHistories.ToList());
        //}

        // GET: CheckoutHistories with search string
        public ActionResult Index(string searchString)
        {
            try
            {
                IEnumerable <CheckoutHistory> checkoutHistories = new List <CheckoutHistory>();
                if (!String.IsNullOrEmpty(searchString))
                {
                    if (Int32.TryParse(searchString, out int searchInt))
                    {
                        checkoutHistories = db.CheckoutHistories.Include(c => c.Asset).Include(c => c.Patron)
                                            .Where(x => x.Asset.AssetId.Equals(searchInt) ||
                                                   x.Patron.PatronId.Equals(searchInt));
                    }
                    else
                    {
                        checkoutHistories = db.CheckoutHistories.Include(c => c.Asset).Include(c => c.Patron)
                                            .Where(x => x.Asset.Name.Contains(searchString) ||
                                                   x.Patron.Forename.Contains(searchString) ||
                                                   x.Patron.Surname.Contains(searchString));
                    }
                }
                else
                {
                    checkoutHistories = db.CheckoutHistories.Include(c => c.Asset).Include(c => c.Patron);
                }

                return(View(checkoutHistories.ToList()));
            }
            catch (Exception ex)
            {
                ViewBag.errorMessage = (DebuggingUtilities.GetExceptionString(ex));
                return(View("../Home/Index"));
            }
        }
コード例 #3
0
        // GET: Equipment with search string
        public ActionResult Index(string searchString, string sortOrder, string currentFilter, int?page)
        {
            ViewBag.CurrentSort = sortOrder;
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            try
            {
                IEnumerable <Equipment> equipment = new List <Equipment>();
                if (!String.IsNullOrEmpty(searchString))
                {
                    if (Int32.TryParse(searchString, out int searchInt))
                    {
                        equipment = db.Assets.OfType <Equipment>()
                                    .Include(a => a.Location)
                                    .Include(a => a.Status)
                                    .Include(a => a.AssetType)
                                    .Where(x => x.AssetId.Equals(searchInt));
                    }
                    else
                    {
                        equipment = db.Assets.OfType <Equipment>()
                                    .Include(a => a.Location)
                                    .Include(a => a.Status)
                                    .Include(a => a.AssetType)
                                    .Where(x => x.Name.Contains(searchString) ||
                                           x.AssetType.Name.Contains(searchString));
                    }
                }
                else
                {
                    equipment = db.Assets.OfType <Equipment>()
                                .Include(a => a.Location)
                                .Include(a => a.Status)
                                .Include(a => a.AssetType);
                }


                //ordering
                ViewBag.NameSortParm      = String.IsNullOrEmpty(sortOrder) ? "name_asc" : "";
                ViewBag.AssetTypeSortParm = String.IsNullOrEmpty(sortOrder) ? "assetType_asc" : "";
                ViewBag.LocationSortParm  = String.IsNullOrEmpty(sortOrder) ? "location_asc" : "";


                switch (sortOrder)
                {
                case "name_asc":
                    equipment = equipment.OrderBy(b => b.Name);
                    break;

                case "assetType_asc":
                    equipment = equipment.OrderBy(b => b.AssetType);
                    break;

                case "location_asc":
                    equipment = equipment.OrderBy(b => b.Location.Name);
                    break;

                default:
                    equipment = equipment.OrderBy(b => b.AssetId);
                    break;
                }

                int pageSize   = 20;
                int pageNumber = (page ?? 1);
                return(View(equipment.ToPagedList(pageNumber, pageSize)));
            }
            catch (Exception ex)
            {
                ViewBag.errorMessage = (DebuggingUtilities.GetExceptionString(ex));
                return(View("../Home/Index"));
            }
        }