/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> List(OnlineCustomerSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers)) { return(await AccessDeniedDataTablesJson()); } //prepare model var model = await _customerModelFactory.PrepareOnlineCustomerListModelAsync(searchModel); return(Json(model)); }
public virtual IActionResult List(OnlineCustomerSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedKendoGridJson()); } //prepare model var model = _customerModelFactory.PrepareOnlineCustomerListModel(searchModel); return(Json(model)); }
/// <summary> /// Prepare online customer search model /// </summary> /// <param name="searchModel">Online customer search model</param> /// <returns>Online customer search model</returns> public virtual OnlineCustomerSearchModel PrepareOnlineCustomerSearchModel(OnlineCustomerSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <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); }