public ActionResult Edit(int id, WinterGear item)
        {
            try
            {
                WinterGearRepository repository = new WinterGearRepository(_dataSettings);

                WinterGear updateItem = new WinterGear()
                {
                    Id        = id,
                    Name      = item.Name,
                    Weight    = item.Weight,
                    GearType  = item.GearType,
                    Condition = item.Condition,
                };

                using (repository)
                {
                    repository.Update(updateItem);
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ViewData["errorOccurred"] = true;
                ViewData["errorMessage"]  = ex.Message;

                return(View());
            }
        }
        public ActionResult Delete(int id)
        {
            WinterGearRepository repository = new WinterGearRepository(_dataSettings);

            WinterGear winterGearItem;

            using (repository)
            {
                winterGearItem = repository.SelectOne(id);
            }

            return(View(winterGearItem));
        }
        private IEnumerable <string> listOfGearTypes()
        {
            IEnumerable <WinterGear> gearItems;

            using (WinterGearRepository gearRepository = new WinterGearRepository(_dataSettings))
            {
                gearItems = gearRepository.SelectAll() as IList <WinterGear>;
            }

            IEnumerable <string> gearTypes = gearItems.Select(gearItem => gearItem.GearType).Distinct().OrderBy(gt => gt);

            return(gearTypes);
        }
        public ActionResult Delete(int id, WinterGear item)
        {
            try
            {
                WinterGearRepository repository = new WinterGearRepository(_dataSettings);

                using (repository)
                {
                    repository.Delete(id);
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ViewData["errorOccurred"] = true;
                ViewData["errorMessage"]  = ex.Message;

                return(View());
            }
        }
        public ActionResult Index(SearchViewModel searchModel)
        {
            WinterGearRepository gearRepository = new WinterGearRepository(_dataSettings);

            IEnumerable <WinterGear> gearItems;

            using (gearRepository)
            {
                gearItems = gearRepository.SelectAll() as IList <WinterGear>;
            }

            if (!string.IsNullOrWhiteSpace(searchModel.SearchCriteria))
            {
                gearItems = gearItems.Where(item => item.Name.ToUpper().Contains(searchModel.SearchCriteria.ToUpper()));
            }

            if (!string.IsNullOrWhiteSpace(searchModel.GearTypeFilter))
            {
                gearItems = gearItems.Where(item => item.GearType == searchModel.GearTypeFilter);
            }

            switch (searchModel.SortOrder)
            {
            case "name":
                // order names ascending
                gearItems = gearItems.OrderBy(i => i.Name);
                break;

            case "condition":
                // order condition descending
                gearItems = gearItems.OrderByDescending(i => i.Condition);
                break;

            case "weight":
                // order weight ascending
                gearItems = gearItems.OrderBy(i => i.Weight);
                break;

            case "gearType":
                // order gearType ascending
                gearItems = gearItems.OrderBy(i => i.GearType);
                break;

            default:
                // order id ascending
                gearItems = gearItems.OrderBy(i => i.Id);
                break;
            }

            if (searchModel.FlipOrder)
            {
                gearItems = gearItems.Reverse();
            }

            int pageNumber = (searchModel.PageNumber ?? 1);

            int itemsPerPage = (searchModel.PageSize ?? 10);

            IPaginator <WinterGear> paginator = new Paginator <WinterGear>(gearItems, itemsPerPage, pageNumber);

            ViewBag.paginator = paginator;

            ViewBag.sortOrder      = searchModel.SortOrder;
            ViewBag.flipOrder      = searchModel.FlipOrder;
            ViewBag.gearTypes      = listOfGearTypes();
            ViewBag.gearTypeFilter = searchModel.GearTypeFilter;
            ViewBag.searchCriteria = searchModel.SearchCriteria;
            ViewBag.isSearch       = true;

            return(View(paginator.GetItems()));
        }