public ActionResult AffiliatedCustomerList(int affiliateId, GridCommand command) { var model = new GridModel <AffiliateModel.AffiliatedCustomerModel>(); var q = new CustomerSearchQuery { AffiliateId = affiliateId, PageIndex = command.Page - 1, PageSize = command.PageSize }; var customers = _customerService.SearchCustomers(q); model.Data = customers.Select(customer => { var customerModel = new AffiliateModel.AffiliatedCustomerModel { Id = customer.Id, Email = customer.Email, Username = customer.Username, FullName = customer.GetFullName() }; return(customerModel); }); model.Total = customers.TotalCount; return(new JsonResult { Data = model }); }
public ActionResult CurrentCarts(GridCommand command) { var gridModel = new GridModel <ShoppingCartModel>(); var query = new CustomerSearchQuery { OnlyWithCart = true, CartType = ShoppingCartType.ShoppingCart, PageIndex = command.Page - 1, PageSize = command.PageSize }; var guestStr = T("Admin.Customers.Guest").Text; var customers = _customerService.SearchCustomers(query); gridModel.Data = customers.Select(x => { return(new ShoppingCartModel { CustomerId = x.Id, CustomerEmail = x.IsGuest() ? guestStr : x.Email, TotalItems = x.CountProductsInCart(ShoppingCartType.ShoppingCart) }); }); gridModel.Total = customers.TotalCount; return(new JsonResult { Data = gridModel }); }
public IEnumerable<Customer> Get(DateTime? lastModified, string userName) { var searchQuery = new CustomerSearchQuery() { LastModified = lastModified, Username = userName }; var dataService = ServiceProvider.Get<ICustomersDataService>(); return dataService.GetCustomers(1, searchQuery); }
public IActionResult GetCustomers(string name, string city, int page, int?pages) { if (pages == null) { pages = new CustomerSearchCountPagesQuery().Get(_context, name, city); } var query = new CustomerSearchQuery().Get(_context, name, city, page); return(PartialView("_CustomerSearchResultPartial", new CustomerSearchViewModel() { Customers = query.Customers, Page = page, Name = name, City = city, Pages = pages })); }
public ActionResult AffiliatedCustomerList(int affiliateId, GridCommand command) { var model = new GridModel <AffiliateModel.AffiliatedCustomerModel>(); if (_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates)) { var q = new CustomerSearchQuery { AffiliateId = affiliateId, PageIndex = command.Page - 1, PageSize = command.PageSize }; var customers = _customerService.SearchCustomers(q); model.Data = customers.Select(customer => { var customerModel = new AffiliateModel.AffiliatedCustomerModel { Id = customer.Id, Email = customer.Email, Username = customer.Username, FullName = customer.GetFullName() }; return(customerModel); }); model.Total = customers.TotalCount; } else { model.Data = Enumerable.Empty <AffiliateModel.AffiliatedCustomerModel>(); NotifyAccessDenied(); } return(new JsonResult { Data = model }); }
public ActionResult CurrentCarts(GridCommand command) { var gridModel = new GridModel <ShoppingCartModel>(); if (Services.Permissions.Authorize(StandardPermissionProvider.ManageOrders)) { var q = new CustomerSearchQuery { OnlyWithCart = true, CartType = ShoppingCartType.ShoppingCart, PageIndex = command.Page - 1, PageSize = command.PageSize }; var guestStr = T("Admin.Customers.Guest").Text; var customers = _customerService.SearchCustomers(q); gridModel.Data = customers.Select(x => { return(new ShoppingCartModel { CustomerId = x.Id, CustomerEmail = x.IsGuest() ? guestStr : x.Email, TotalItems = x.CountProductsInCart(ShoppingCartType.ShoppingCart) }); }); gridModel.Total = customers.TotalCount; } else { gridModel.Data = Enumerable.Empty <ShoppingCartModel>(); NotifyAccessDenied(); } return(new JsonResult { Data = gridModel }); }
public Customer[] GetCustomers(int tenantId, CustomerSearchQuery searchQuery) { var customers = new List<Customer>(); var sql = GetReadSql(); ExecuteRreader(sql, CommandType.Text, command => { AddTenantParameters(command, tenantId); }, reader => { while (reader.Read()) { var customer = CreateCustomerFromData(reader); customers.Add(customer); } }); return customers.ToArray(); }
private void ReloadCustomers() { var ds = new CustomersDataService(); var query = new CustomerSearchQuery(); CustomersGrid.DataSource = ds.GetCustomers(GetTenantId(), query); }
public ActionResult Picker(EntityPickerModel model, FormCollection form) { try { var languageId = model.LanguageId == 0 ? Services.WorkContext.WorkingLanguage.Id : model.LanguageId; var disableIf = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList(); var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList(); var selected = model.Selected.SplitSafe(","); var returnSku = model.ReturnField.IsCaseInsensitiveEqual("sku"); using (var scope = new DbContextScope(Services.DbContext, autoDetectChanges: false, proxyCreation: true, validateOnSave: false, forceNoTracking: true)) { if (model.EntityType.IsCaseInsensitiveEqual("product")) { model.SearchTerm = model.SearchTerm.TrimSafe(); var hasPermission = Services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog); var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct"); var disableIfGroupedProduct = disableIf.Contains("groupedproduct"); var labelTextGrouped = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Text; var labelTextBundled = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Text; var sku = T("Products.Sku").Text; var fields = new List <string> { "name" }; if (_searchSettings.SearchFields.Contains("sku")) { fields.Add("sku"); } if (_searchSettings.SearchFields.Contains("shortdescription")) { fields.Add("shortdescription"); } var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchTerm) .HasStoreId(model.StoreId); if (!hasPermission) { searchQuery = searchQuery.VisibleOnly(Services.WorkContext.CurrentCustomer); } if (model.ProductTypeId > 0) { searchQuery = searchQuery.IsProductType((ProductType)model.ProductTypeId); } if (model.ManufacturerId != 0) { searchQuery = searchQuery.WithManufacturerIds(null, model.ManufacturerId); } if (model.CategoryId != 0) { var node = _categoryService.GetCategoryTree(model.CategoryId, true); if (node != null) { searchQuery = searchQuery.WithCategoryIds(null, node.Flatten(true).Select(x => x.Id).ToArray()); } } var skip = model.PageIndex * model.PageSize; var query = _catalogSearchService.PrepareQuery(searchQuery); var products = query .Select(x => new { x.Id, x.Sku, x.Name, x.Published, x.ProductTypeId, x.MainPictureId }) .OrderBy(x => x.Name) .Skip(() => skip) .Take(() => model.PageSize) .ToList(); var allPictureIds = products.Select(x => x.MainPictureId.GetValueOrDefault()); var allPictureInfos = _pictureService.GetPictureInfos(allPictureIds); model.SearchResult = products .Select(x => { var item = new EntityPickerModel.SearchResultModel { Id = x.Id, Title = x.Name, Summary = x.Sku, SummaryTitle = "{0}: {1}".FormatInvariant(sku, x.Sku.NaIfEmpty()), Published = hasPermission ? x.Published : (bool?)null, ReturnValue = returnSku ? x.Sku : x.Id.ToString() }; item.Selected = selected.Contains(item.ReturnValue); if (disableIfNotSimpleProduct) { item.Disable = x.ProductTypeId != (int)ProductType.SimpleProduct; } else if (disableIfGroupedProduct) { item.Disable = x.ProductTypeId == (int)ProductType.GroupedProduct; } if (!item.Disable && disableIds.Contains(x.Id)) { item.Disable = true; } if (x.ProductTypeId == (int)ProductType.GroupedProduct) { item.LabelText = labelTextGrouped; item.LabelClassName = "badge-success"; } else if (x.ProductTypeId == (int)ProductType.BundledProduct) { item.LabelText = labelTextBundled; item.LabelClassName = "badge-info"; } var pictureInfo = allPictureInfos.Get(x.MainPictureId.GetValueOrDefault()); var fallbackType = _catalogSettings.HideProductDefaultPictures ? FallbackPictureType.NoFallback : FallbackPictureType.Entity; item.ImageUrl = _pictureService.GetUrl( allPictureInfos.Get(x.MainPictureId.GetValueOrDefault()), _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, fallbackType); return(item); }) .ToList(); } else if (model.EntityType.IsCaseInsensitiveEqual("category")) { var categories = _categoryService.GetAllCategories(model.SearchTerm, showHidden: true); var allPictureIds = categories.Select(x => x.PictureId.GetValueOrDefault()); var allPictureInfos = _pictureService.GetPictureInfos(allPictureIds); model.SearchResult = categories .Select(x => { var path = ((ICategoryNode)x).GetCategoryPath(_categoryService, languageId, "({0})"); var item = new EntityPickerModel.SearchResultModel { Id = x.Id, Title = x.Name, Summary = path, SummaryTitle = path, Published = x.Published, ReturnValue = x.Id.ToString(), Selected = selected.Contains(x.Id.ToString()), Disable = disableIds.Contains(x.Id) }; if (x.Alias.HasValue()) { item.LabelText = x.Alias; item.LabelClassName = "badge-secondary"; } var pictureInfo = allPictureInfos.Get(x.PictureId.GetValueOrDefault()); var fallbackType = _catalogSettings.HideProductDefaultPictures ? FallbackPictureType.NoFallback : FallbackPictureType.Entity; item.ImageUrl = _pictureService.GetUrl( allPictureInfos.Get(x.PictureId.GetValueOrDefault()), _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, fallbackType); return(item); }) .ToList(); } else if (model.EntityType.IsCaseInsensitiveEqual("manufacturer")) { var manufacturers = _manufacturerService.GetAllManufacturers(model.SearchTerm, model.PageIndex, model.PageSize, showHidden: true); var allPictureIds = manufacturers.Select(x => x.PictureId.GetValueOrDefault()); var allPictureInfos = _pictureService.GetPictureInfos(allPictureIds); model.SearchResult = manufacturers .Select(x => { var item = new EntityPickerModel.SearchResultModel { Id = x.Id, Title = x.Name, Published = x.Published, ReturnValue = x.Id.ToString(), Selected = selected.Contains(x.Id.ToString()), Disable = disableIds.Contains(x.Id) }; var pictureInfo = allPictureInfos.Get(x.PictureId.GetValueOrDefault()); var fallbackType = _catalogSettings.HideProductDefaultPictures ? FallbackPictureType.NoFallback : FallbackPictureType.Entity; item.ImageUrl = _pictureService.GetUrl( allPictureInfos.Get(x.PictureId.GetValueOrDefault()), _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, fallbackType); return(item); }) .ToList(); } else if (model.EntityType.IsCaseInsensitiveEqual("customer")) { var registeredRoleId = _customerService.GetCustomerRoleBySystemName("Registered").Id; var searchTermName = string.Empty; var searchTermEmail = string.Empty; var searchTermCustomerNumber = string.Empty; if (model.CustomerSearchType.IsCaseInsensitiveEqual("Name")) { searchTermName = model.SearchTerm; } else if (model.CustomerSearchType.IsCaseInsensitiveEqual("Email")) { searchTermEmail = model.SearchTerm; } else if (model.CustomerSearchType.IsCaseInsensitiveEqual("CustomerNumber")) { searchTermCustomerNumber = model.SearchTerm; } var q = new CustomerSearchQuery { SearchTerm = searchTermName, Email = searchTermEmail, CustomerNumber = searchTermCustomerNumber, CustomerRoleIds = new int[] { registeredRoleId }, PageIndex = model.PageIndex, PageSize = model.PageSize }; var customers = _customerService.SearchCustomers(q); model.SearchResult = customers .Select(x => { var fullName = x.GetFullName(); var item = new EntityPickerModel.SearchResultModel { Id = x.Id, ReturnValue = x.Id.ToString(), Title = x.Username.NullEmpty() ?? x.Email, Summary = fullName, SummaryTitle = fullName, Published = true, Selected = selected.Contains(x.Id.ToString()), Disable = disableIds.Contains(x.Id) }; return(item); }) .ToList(); } } } catch (Exception ex) { NotifyError(ex.ToAllMessages()); } return(PartialView("Picker.List", model)); }
public Window1() { _customerSearchQuery = new CustomerSearchQuery(); InitializeComponent(); }