public ActionResult Index(SearchCategoryModel Model, int?page) { var pageNumber = page ?? 1; int total = new int(); List <CategoryViewModel> lstModel = new List <CategoryViewModel>(); List <GetCatetoryModel> lstcombobox = new List <GetCatetoryModel>(); if (!string.IsNullOrEmpty(Session["code_category"] as string)) { Model.code = Session["code_category"].ToString(); } if (!string.IsNullOrEmpty(Session["name_category"] as string)) { Model.name = Session["name_category"].ToString(); } if (Session["parent_id_category"] as int? != null) { Model.parent_id = (int)Session["parent_id_category"]; } _categoryBLL.Search(Model, out lstModel, out total, pageNumber); var list = new StaticPagedList <CategoryViewModel>(lstModel, pageNumber, 15, total); ViewBag.ListSearch = lstModel.OrderByDescending(x => x.id); _categoryBLL.GetCategory(true, out lstcombobox); ViewBag.lstcombobox = lstcombobox; ViewBag.page = 0; if (page != null) { ViewBag.page = pageNumber - 1; } return(View(new Tuple <SearchCategoryModel, IPagedList <CategoryViewModel> >(Model, list))); }
public async Task <IActionResult> Get([FromQuery] SearchCategoryModel model) { var result = await _categoryService.GetAsync(pageIndex : model.PageIndex, pageSize : model.PageSize, filter : x => x.DelFlg == false); if (result == null) { return(NotFound()); } return(Ok(result)); }
public ActionResult SearchCategory() { SearchCategoryModel returnModel = new SearchCategoryModel(); returnModel.StoreOptions = Utility.GetStoresOptions(User, "All"); returnModel.SetSharedData(User); if (returnModel.Role == RoleTypes.SubAdmin) { returnModel.StoreId = (returnModel as BaseViewModel).StoreId; } return(PartialView("_SearchCategory", returnModel)); }
public int Search(SearchCategoryModel searchCondition, out List <CategoryViewModel> lstModel, out int total, int _page) { _page = _page * 15 - 15; int returnCode = (int)Common.ReturnCode.Succeed; lstModel = new List <CategoryViewModel>(); total = new int(); try { string sql = "SELECT cate.`id`, cate_parent.`name` parent_name, cate.`code`, cate.`name`, cate.`description` "; sql += "FROM `product_category` cate "; sql += "LEFT JOIN (SELECT `id`, `name` FROM `product_category`) cate_parent "; sql += "ON cate.`parent_id` = cate_parent.`id` WHERE TRUE "; string _sql = "SELECT COUNT(cate.`id`) "; _sql += "FROM `product_category` cate "; _sql += "LEFT JOIN (SELECT `id`, `name` FROM `product_category`) cate_parent "; _sql += "ON cate.`parent_id` = cate_parent.`id` WHERE TRUE "; if (!string.IsNullOrEmpty(searchCondition.parent_id.ToString())) { sql += "AND (cate.`id` = @parent_id OR cate.`id` IN (SELECT `id` FROM tuankhai_freshernet.product_category WHERE `parent_id` = @parent_id)) "; _sql += "AND (cate.`id` = @parent_id OR cate.`id` IN (SELECT `id` FROM tuankhai_freshernet.product_category WHERE `parent_id` = @parent_id)) "; } if (!string.IsNullOrEmpty(searchCondition.code)) { sql += "AND cate.`code` LIKE @code "; _sql += "AND cate.`code` LIKE @code "; } if (!string.IsNullOrEmpty(searchCondition.name)) { sql += "AND cate.`name` LIKE @name "; _sql += "AND cate.`name` LIKE @name "; } sql += " ORDER BY cate.`id` ASC LIMIT @page,15"; lstModel = _db.Query <CategoryViewModel>(sql, new { parent_id = searchCondition.parent_id, code = '%' + searchCondition.code + '%', name = '%' + searchCondition.name + '%', page = _page }).ToList(); total = _db.ExecuteScalar <int>(_sql, new { parent_id = searchCondition.parent_id, code = '%' + searchCondition.code + '%', name = '%' + searchCondition.name + '%', page = _page }); } catch (Exception ex) { return(returnCode = (int)Common.ReturnCode.UnSuccess); } return(returnCode); }
public ActionResult IndexPost(SearchCategoryModel Model, int?page) { var pageNumber = page ?? 1; List <CategoryViewModel> lstModel = new List <CategoryViewModel>(); List <GetCatetoryModel> lstcombobox = new List <GetCatetoryModel>(); int total = new int(); _categoryBLL.Search(Model, out lstModel, out total, pageNumber); var list = new StaticPagedList <CategoryViewModel>(lstModel, pageNumber, 15, total); ViewBag.ListSearch = lstModel.OrderByDescending(x => x.id); Session["code_category"] = Model.code; Session["name_category"] = Model.name; Session["parent_id_category"] = Model.parent_id; TempData["CountResult"] = total.ToString() + " row(s) found!"; _categoryBLL.GetCategory(true, out lstcombobox); ViewBag.lstcombobox = lstcombobox; return(View(new Tuple <SearchCategoryModel, IPagedList <CategoryViewModel> >(Model, list))); }
public ActionResult SearchCategoryResults(SearchCategoryModel model) { SearchCategoriesViewModel returnModel = new SearchCategoriesViewModel(); var response = AsyncHelpers.RunSync <JObject>(() => ApiCall.CallApi("api/Admin/SearchCategories", User, null, true, false, null, "CategoryName=" + model.CategoryName, "StoreId=" + model.StoreId, "CatId=null")); if (response == null || response is Error) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, (response as Error).ErrorMessage)); } else { returnModel = response.GetValue("Result").ToObject <SearchCategoriesViewModel>(); } var tempCats = returnModel.Categories.ToList(); foreach (var cat in returnModel.Categories) { cat.Name = cat.GetFormattedBreadCrumb(tempCats); } returnModel.SetSharedData(User); return(PartialView("_SearchCategoryResults", returnModel)); }
public ActionResult List(DataSourceRequest command, SearchCategoryModel model) { if (!_permissionService.Authorize(PermissionProvider.CategoryManagement)) { return(AccessDeniedView()); } var categorys = _categoryService.GetAllCategoryAsync(searchByCategoryName: model.CategoryName, pageIndex: command.Page - 1, pageSize: command.PageSize).Result; var gridModel = new DataSourceResult { Data = categorys.Select(s => new CategoryModel { Id = s.Id, Name = s.Name, Note = s.Note, DisplayOrder = s.DisplayOrder }), Total = categorys.TotalCount }; // Return the result as JSON return(Json(gridModel)); }
public int Search(SearchCategoryModel searchCondition, out List <CategoryViewModel> lstModel, out int total, int _page) { return(_categoryDAO.Search(searchCondition, out lstModel, out total, _page)); }
public ActionResult SearchResultsPage(SearchModel model, bool LowerButtonClick, string CategorySeName, int?tag = null) { var categoryId = _urlRecordService.GetBySlug(CategorySeName); Category categor; if (categoryId == null && model.SelectedCategoryAttributes == null && model.CustomerAttributes == null) { return(RedirectToAction("HomePage")); } else { if (model.SelectedCategoryAttributes != null && model.CustomerAttributes != null) { categor = _categoryService.GetCategoryById(model.SelectedCategoryAttributes.CategoryId); } else { categor = _categoryService.GetCategoryById(categoryId.EntityId); } } var a = 10; IList <SearchProductAttributeValue> attributesToSearch = null; // = ParceProductAttributesToSearch(model); IList <SearchProductAttributeValue> customerAttributes = null; // = ParceCustomerAttributesToSearch(model); var searchModelFull = new SearchModelFull(); searchModelFull.LowerButtonClick = LowerButtonClick; if (model.SelectedCategoryAttributes != null) { attributesToSearch = ParceProductAttributesToSearch(model, true); searchModelFull.SelectedCategoryAttributes = RestoreSearchModel(model.SelectedCategoryAttributes); if (model.DetailedSelectedCategoryAttributes != null) { ((List <SearchProductAttributeValue>)attributesToSearch).AddRange(ParceProductAttributesToSearch(model, false)); searchModelFull.DetailedSelectedCategoryAttributes = RestoreSearchModel(model.DetailedSelectedCategoryAttributes); } else { searchModelFull.DetailedSelectedCategoryAttributes = PrepareSearchCategoryModel(categor.Id, false); searchModelFull.DetailedSelectedCategoryAttributes.CategoryId = categor.Id; } if (model.SelectedAdditionalCategoryAttributes != null) { ((List <SearchProductAttributeValue>)attributesToSearch).AddRange(ParceProductAttributesToSearch(model, false, true)); searchModelFull.SelectedAdditionalCategoryAttributes = RestoreSearchModel(model.SelectedAdditionalCategoryAttributes); } else { searchModelFull.SelectedAdditionalCategoryAttributes = PrepareSearchCategoryModel(categor.Id, false, true); searchModelFull.SelectedAdditionalCategoryAttributes.CategoryId = categor.Id; } } else { searchModelFull.DetailedSelectedCategoryAttributes = PrepareSearchCategoryModel(categor.Id, false); searchModelFull.DetailedSelectedCategoryAttributes.CategoryId = categor.Id; searchModelFull.SelectedAdditionalCategoryAttributes = PrepareSearchCategoryModel(categor.Id, false, true); searchModelFull.SelectedAdditionalCategoryAttributes.CategoryId = categor.Id; searchModelFull.SelectedCategoryAttributes = PrepareSearchCategoryModel(categor.Id, true); } if (model.CustomerAttributes == null) { searchModelFull.CustomerAttributes = PrepareCustomerAttributes(); } else { customerAttributes = ParceCustomerAttributesToSearch(model); searchModelFull.CustomerAttributes = RestoreCustomerSearchAttributes(model.CustomerAttributes); } searchModelFull.CustomerAttributes.Cities = _cityService.GetAllCities().OrderBy(x => x.Title).Select(x => new CityModel() { Id = x.Id, Title = x.Title }).ToList(); searchModelFull.CustomerAttributes.Currencies = _currencyService.GetAllCurrencies().Select(x => new CurrencyModel() { Id = x.Id, Name = x.CurrencyCode }).ToList(); int regionId = 0; if (model.CustomerAttributes != null && model.CustomerAttributes.CityId != 0) { var city = _cityService.GetById(model.CustomerAttributes.CityId); if (city != null) { regionId = city.RegionId; } } var bestProducts = _productService.SearchProductsWithAttributes(0, ProductSortingEnum.CreatedOn, 0, short.MaxValue, 0, categor.Id, 0, 0, 0, null, null).Where(x => x.FeaturedProduct); var products = _productService.SearchProductsWithAttributes(0, ProductSortingEnum.CreatedOn, 0, short.MaxValue, tag.GetValueOrDefault(), categor.Id, 0, 0, regionId, attributesToSearch, customerAttributes);//дописать linq фильтр по параметрам var searchActivity = _customerActivityService.InsertActivity("PublicStore.SearchProduct", _localizationService.GetResource("ITBSFA.SearchLog.Message"), _workContext.CurrentCustomer, Request.UrlReferrer == null ? "" : Request.UrlReferrer.ToString(), 0); _searchLogService.LogSearchQuerryWithParameters(attributesToSearch, customerAttributes, searchActivity.Id, regionId, 0, categor.Id, tag.GetValueOrDefault(), 0, 0); var productsTags = products.SelectMany(x => x.ProductTags).DistinctBy(x => x.Name); foreach (var productsTag in productsTags) { searchModelFull.ProductTags.Add(new ProductTagModel() { Name = productsTag.Name, Id = productsTag.Id }); } var categories = _categoryService.GetAllCategories(); searchModelFull.Categories = new List <SearchCategoryModel>(); foreach (var category in categories) { var categoryModel = new SearchCategoryModel(); categoryModel.CateogyTitle = category.Name; categoryModel.CategoryId = category.Id; categoryModel.SeName = category.GetSeName(_workContext.WorkingLanguage.Id); searchModelFull.Categories.Add(categoryModel); } searchModelFull.Products = new List <OffersProductModel>(); if (products != null && products.Any()) { searchModelFull.Products = new List <OffersProductModel>(); foreach (var i in products) { var productModel = new OffersProductModel() { Id = i.Id, Rating = Math.Round(i.Rating ?? 0), BankRating = Math.Round(i.Customer.Rating ?? 0), Name = i.Name, ProductAttributeValue = i.ProductAttributes.FirstOrDefault(x => x.CategoryProductAttribute.ProductBoxAttribute), MetaTitle = i.MetaTitle, PictureThumbnailUrl = _pictureService.GetPictureUrl(i.Customer.ProviderLogoId.GetValueOrDefault(), 100, false), ShortDescription = i.ShortDescription, FullDescription = i.FullDescription, SeName = i.GetSeName(), OrderingLink = i.OrderLink, }; searchModelFull.Products.Add(productModel); } } if (bestProducts.Any()) { searchModelFull.BestProducts = new List <OffersProductModel>(); foreach (var i in bestProducts) { var productModel = new OffersProductModel() { Id = i.Id, Rating = Math.Round(i.Rating ?? 0), BankRating = Math.Round(i.Customer.Rating ?? 0), Name = i.Name, ProductAttributeValue = i.ProductAttributes.FirstOrDefault(x => x.CategoryProductAttribute.ProductBoxAttribute), MetaTitle = i.MetaTitle, PictureThumbnailUrl = _pictureService.GetPictureUrl(i.Customer.ProviderLogoId.GetValueOrDefault(), 100, false), ShortDescription = i.ShortDescription, FullDescription = i.FullDescription, SeName = i.GetSeName(), OrderingLink = i.OrderLink, }; searchModelFull.BestProducts.Add(productModel); } } return(View(searchModelFull)); }
// GET: Categories public ActionResult Index(SearchCategoryModel searchCategoryModel) { int pageSize = 10; //get select list of Author ID List <SelectListItem> selectListItemsAuthor = new List <SelectListItem>(); foreach (Author item in authorService.GetAll()) { selectListItemsAuthor.Add(new SelectListItem { Text = item.Name, Value = Convert.ToString(item.ID) }); } ViewBag.authorIDList = new SelectList(selectListItemsAuthor, "Value", "Text", -1); // get list of category ViewBag.listCategory = categoryService.GetAll(); // get selected list of category List <SelectListItem> selectListItems = new List <SelectListItem>(); foreach (Category cate in categoryService.GetAll()) { selectListItems.Add(new SelectListItem { Text = cate.Name, Value = Convert.ToString(cate.ID) }); } ViewBag.categoryID = new SelectList(selectListItems, "Value", "Text", -1); // get selected list of selectBy Dictionary <string, int> dicSortType = new Dictionary <string, int> { { "Thứ tự theo giá: Cao đến thấp", (int)sortType.orderByPriceHigh }, { "Thứ tự theo giá: Thấp đến cao", (int)sortType.orderByPriceLow }, { "Thứ tự theo sản phẩm mới", (int)sortType.orderByNew }, { "Thứ tự theo mua nhiều", (int)sortType.orderBySell }, //{ "Thứ tự theo đánh giá", (int)sortType.orderByRate } }; List <SelectListItem> selectListItemsOrderBy = new List <SelectListItem>(); foreach (KeyValuePair <string, int> entry in dicSortType) { selectListItemsOrderBy.Add(new SelectListItem { Text = entry.Key, Value = Convert.ToString(entry.Value) }); } ViewBag.listSortType = new SelectList(selectListItemsOrderBy, "Value", "Text"); // get all books // ID = -1 get books of all category var allWarehouseBooks = bookService.GetBooksBySomeCondition(searchCategoryModel.SearchValue, searchCategoryModel.PriceFrom, searchCategoryModel.PriceTo, searchCategoryModel.AuthorID, searchCategoryModel.ID); switch (searchCategoryModel.sortBy) { case (int)sortType.orderByPriceHigh: allWarehouseBooks = allWarehouseBooks.OrderByDescending(b => b.Price); break; case (int)sortType.orderByPriceLow: allWarehouseBooks = allWarehouseBooks.OrderBy(b => b.Price); break; case (int)sortType.orderBySell: allWarehouseBooks = bookService.GetBestSellerBooks(allWarehouseBooks, DateTime.MinValue, DateTime.Today); break; } ViewBag.pageCount = Math.Ceiling(allWarehouseBooks.Count() / (pageSize * 1.0)); int startIndex = pageSize * (searchCategoryModel.Page - 1); // phan trang ViewBag.allBooks = allWarehouseBooks.Skip(startIndex).Take(pageSize).ToList(); return(View(searchCategoryModel)); }