public ActionResult List(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var customers = _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-_customerSettings.OnlineCustomerMinutes),
                                                                null, command.Page - 1, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data = customers.Select(x =>
                {
                    return(new OnlineCustomerModel()
                    {
                        Id = x.Id,
                        CustomerInfo = x.IsRegistered() ? x.Email : _localizationService.GetResource("Admin.Customers.Guest"),
                        LastIpAddress = x.LastIpAddress,
                        Location = _geoLookupService.LookupCountryName(x.LastIpAddress),
                        LastActivityDate = _dateTimeHelper.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc),
                        LastVisitedPage = _customerSettings.StoreLastVisitedPage ?
                                          x.GetAttribute <string>(SystemCustomerAttributeNames.LastVisitedPage) :
                                          _localizationService.GetResource("Admin.Customers.OnlineCustomers.Fields.LastVisitedPage.Disabled")
                    });
                }),
                Total = customers.TotalCount
            };

            return(Json(gridModel));
        }
Пример #2
0
        public async Task <IActionResult> List(DataSourceRequest command)
        {
            var customers = await _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-_customerSettings.OnlineCustomerMinutes),
                                                                      null, 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 : _localizationService.GetResource("Admin.Customers.Guest"),
                    LastIpAddress    = x.LastIpAddress,
                    Location         = _geoLookupService.LookupCountryName(x.LastIpAddress),
                    LastActivityDate = _dateTimeHelper.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc),
                    LastVisitedPage  = _customerSettings.StoreLastVisitedPage ?
                                       x.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.LastVisitedPage) :
                                       _localizationService.GetResource("Admin.Customers.OnlineCustomers.Fields.LastVisitedPage.Disabled")
                };
                items.Add(item);
            }

            var gridModel = new DataSourceResult {
                Data  = items,
                Total = customers.TotalCount
            };

            return(Json(gridModel));
        }
Пример #3
0
        public HttpResponseMessage List(HttpRequestMessage request, int pageIndex = 0, int pageSize = int.MaxValue)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No items found");
                if (true)
                {
                    var customers = _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(_customerSettings.OnlineCustomerMinutes),
                                                                        null, pageIndex, pageSize);
                    var gridModel = new DataSourceResult
                    {
                        Data = customers.Select(x => new OnlineCustomerVM
                        {
                            Id = x.Id,
                            CustomerInfo = x.IsRegistered() ? x.Email : _localizationService.GetResource("Admin.Customers.Guest"),
                            LastIpAddress = x.LastIpAddress,
                            Location = _geoLookupService.LookupCountryName(x.LastIpAddress),
                            LastActivityDate = _dateTimeHelper.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc),
                            LastVisitedPage = _customerSettings.StoreLastVisitedPage ?
                                              x.GetAttribute <string>(SystemCustomerAttributeNames.LastVisitedPage, _genericAttributeService) :
                                              _localizationService.GetResource("Admin.Customers.OnlineCustomers.Fields.LastVisitedPage.Disabled")
                        }),
                        Total = customers.TotalCount
                    };

                    response = request.CreateResponse <DataSourceResult>(HttpStatusCode.OK, gridModel);
                }
                return response;
            }));
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
 /// <summary>
 /// Get country name
 /// </summary>
 /// <param name="ipAddress">IP address</param>
 /// <returns>Country name</returns>
 public string LookupCountryName(string ipAddress)
 {
     return(_geoLookupService.LookupCountryName(ipAddress));
 }