Example #1
0
        public RegionListModel FindRegionsListModel(int companyId, int index, int pageNo, int pageSize, string search)
        {
            var model = new RegionListModel();

            decimal numValue = 0;
            bool    bGotNum  = decimal.TryParse(search, out numValue);

            // Do a case-insensitive search
            model.GridIndex = index;
            var allItems = db.FindRegions(companyId, true)
                           .Where(r => r.CompanyId == companyId &&
                                  (string.IsNullOrEmpty(search) ||
                                   (r.RegionName != null && r.RegionName.ToLower().Contains(search.ToLower())) ||
                                   (r.CountryCode != null && r.CountryCode.ToLower().Contains(search.ToLower())) ||
                                   (r.PostCodeFrom != null && r.PostCodeFrom.ToLower().Contains(search.ToLower())) ||
                                   (r.PostCodeTo != null && r.PostCodeTo.ToLower().Contains(search.ToLower())) ||
                                   (bGotNum && r.FreightRate == numValue)));

            model.TotalRecords = allItems.Count();
            foreach (var item in allItems.Skip((pageNo - 1) * pageSize)
                     .Take(pageSize))
            {
                model.Items.Add(MapToModel(item));
            }
            return(model);
        }
        public ActionResult Delete(int index, int id)
        {
            var model = new RegionListModel();

            model.GridIndex = index;
            try {
                LookupService.DeleteRegion(id);
            } catch (Exception e1) {
                model.Error.SetError(e1);
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }