Mojtaba
Mojtaba

Reputation: 81

How to access Customer table's data in nopcommerce

I want to show Customer table's data of nopcommerce in admin page.
i did write a plugin for that and receive data in controller but in view i have a problem and show me error happened message.
here is my controller code:

  public class UserDetailsController : BasePluginController
{
    private ICustomerService _UserDetail;
    public UserDetailsController(ICustomerService UserDetail)
    {
        _UserDetail = UserDetail;
    }

    public ActionResult Manage()
    {
        return View();
    }

    [HttpPost]
    public ActionResult GetUsers(DataSourceRequest userDetail)
    {
        var details = _UserDetail.GetAllCustomers();
        var gridModel = new DataSourceResult
         {
             Data = details,
             Total = details.Count
         };
        return Json(gridModel);
    }
}

And this is my view code:

   @{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}


<script>
                $(document).ready(function() {
                    $("#user-details").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("GetUsers", "UserDetails"))",
                                    type: "POST",
                                    dataType: "json",

                                },
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "Id",
                                }
                            },
                            requestEnd: function(e) {
                                if (e.type == "update") {
                                    this.read();
                                }
                            },
                            error: function(e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            numeric: false,
                            previousNext: false,
                            info:false
                        },
                        editable: {
                            confirmation: true,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [
                            {
                                field: "Email",
                                title: "User Name",
                                width: 200
                            }, 

                            {
                                command: [
                                    {
                                        name: "edit",
                                        text: "@T("Admin.Common.Edit")"
                                    }, {
                                        name: "destroy",
                                        text: "@T("Admin.Common.Delete")"
                                    }
                                ],
                                width: 200
                            }
                        ]
                    });
                });
</script>




<div id="user-details"></div>

can anybody help me?

Upvotes: 1

Views: 501

Answers (1)

Divyang Desai
Divyang Desai

Reputation: 7866

Change your GetUsers method on this way:

 var details = _UserDetail.GetAllCustomers();

      var gridModel = new DataSourceResult
      {
           Data=details.Select(x=>
           {
             return new UserDetail()
             {
                Email= x.Email
             };
          }),

       Total = details.Count(),
     };

   return Json(gridModel);

Upvotes: 1

Related Questions