public async Task <IActionResult> List(DataSourceRequest command) { var customers = await _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-_customerSettings.OnlineCustomerMinutes), null, _workContext.CurrentCustomer.StaffStoreId, _workContext.CurrentCustomer.SeId, command.Page - 1, command.PageSize); var items = new List <OnlineCustomerModel>(); foreach (var x in customers) { var item = new OnlineCustomerModel() { Id = x.Id, CustomerInfo = !string.IsNullOrEmpty(x.Email) ? x.Email : _translationService.GetResource("Admin.Customers.Guest"), LastIpAddress = x.LastIpAddress, Location = _geoLookupService.CountryName(x.LastIpAddress), LastActivityDate = _dateTimeService.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc), LastVisitedPage = _customerSettings.StoreLastVisitedPage ? x.GetUserFieldFromEntity <string>(SystemCustomerFieldNames.LastVisitedPage) : _translationService.GetResource("Admin.Dashboards.OnlineCustomers.Fields.LastVisitedPage.Disabled") }; items.Add(item); } var gridModel = new DataSourceResult { Data = items, Total = customers.TotalCount }; return(Json(gridModel)); }
/// <summary> /// Prepare paged online customer list model /// </summary> /// <param name="searchModel">Online customer search model</param> /// <returns>Online customer list model</returns> public virtual OnlineCustomerListModel PrepareOnlineCustomerListModel(OnlineCustomerSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter customers var lastActivityFrom = DateTime.UtcNow.AddMinutes(-_customerSettings.OnlineCustomerMinutes); //get online customers var customers = _customerService.GetOnlineCustomers(customerRoleIds: null, lastActivityFromUtc: lastActivityFrom, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare list model var model = new OnlineCustomerListModel { Data = customers.Select(customer => { //fill in model values from the entity var customerModel = new OnlineCustomerModel { Id = customer.Id }; //convert dates to the user time customerModel.LastActivityDate = _dateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) customerModel.CustomerInfo = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); customerModel.LastIpAddress = _customerSettings.StoreIpAddresses ? customer.LastIpAddress : _localizationService.GetResource("Admin.Customers.OnlineCustomers.Fields.IPAddress.Disabled"); customerModel.Location = _geoLookupService.LookupCountryName(customer.LastIpAddress); customerModel.LastVisitedPage = _customerSettings.StoreLastVisitedPage ? _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.LastVisitedPageAttribute) : _localizationService.GetResource("Admin.Customers.OnlineCustomers.Fields.LastVisitedPage.Disabled"); return(customerModel); }), Total = customers.TotalCount }; return(model); }