Compiler Error when using GetAllCustomersAsync

один год назад
Hello

I'm taking my first steps learning plugin development and am following https://docs.nopcommerce.com/en/developer/tutorials/guide-to-creating-a-page-containing-a-reporting-table-of-datatables.html

I'm struggling with the creation of class CustomersByCountry.cs as outlined here https://docs.nopcommerce.com/en/developer/tutorials/guide-to-creating-a-page-containing-a-reporting-table-of-datatables.html#services-customersbycountrycs

I've copied and pasted the code exactly as shown, but am getting compiler errors in the GetCustomersDistributionByCountryAsync method.

Error  CS1061  'Task<IPagedList<Customer>>' does not contain a definition for 'Where' and no accessible extension method 'Where' accepting a first argument of type 'Task<IPagedList<Customer>>' could be found (are you missing a using directive or an assembly reference?)

Error  CS0746  Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.  

Error  CS4034  The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.  

Error  CS1061  'IAddressService' does not contain a definition for 'GetAddressById' and no accessible extension method 'GetAddressById' accepting a first argument of type 'IAddressService' could be found (are you missing a using directive or an assembly reference?)


I have a using System.Linq statement at the top.

I don't know where to begin to try and resolve these errors.  Please can someone advise?

Thanks
один год назад
Something like

        public async Task<List<CustomersDistribution>> GetCustomersDistributionByCountryAsync()
        {
            var customers = await _customerService.GetAllCustomersAsync();
            return await customers.Where(c => c.ShippingAddressId != null)
                .SelectAwait(async c => new
                {
                    (await _countryService.GetCountryByAddressAsync(await _addressService.GetAddressByIdAsync(c.ShippingAddressId ?? 0))).Name,
                    c.Username
                })
                .GroupBy(c => c.Name)
                .SelectAwait(async cbc => new CustomersDistribution {
                    Country = cbc.Key,
                    NoOfCustomers = await cbc.CountAsync()
                }).ToListAsync();
        }

This compiles but but this makes a null error when getting the Country
Which I did not have time to try and debug
This type of code can be too complicated when errors arise
один год назад
Thanks for this.  I got past the initial problem with this code.  But now I cannot get the plugin to appear or copy to the Nop.Web.Plugins folder.  Last time this happened with my first Hello World plugin it was because I had forgotten to set the plugin.json file to "copy if newer".  That's not the problem this time.

I also have a build error \NopCommerce\src\Nop.Plugin.Tutorial.DistOfCustByCountry\..\..\Build\ClearPluginAssemblies.proj" was not found.  Not sure if this is related.  The project still runs OK.

Think the next step is to delete everything and start over, perhaps with the VS template.  Have checked so many things feels like I'm going round in circles at this point.
один год назад
In most case you are best to start with an existing pluign for the nopCommerce version with a similar function and modify it.
Start with either a Payment, Shipping or Misc Plugin

Search and replace the plugin Group.Name without changing any other code and it should build straight away - then you can modify amd add your code
11 месяцев назад
Hey stuartp22 how did you got past the initial error?