Пример #1
0
        public virtual async Task <IActionResult> CustomerList(CompanyCustomerSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get a Company with the specified id
            var company = await _companyService.GetCompanyByIdAsync(searchModel.CompanyId)
                          ?? throw new ArgumentException("No Company found with the specified id");

            //prepare model
            var model = await _companyModelFactory.PrepareCompanyCustomerListModelAsync(searchModel, company);

            return(Json(model));
        }
Пример #2
0
        protected virtual CompanyCustomerSearchModel PrepareCompanyCustomerSearchModel(CompanyCustomerSearchModel searchModel, Company company)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (company == null)
            {
                throw new ArgumentNullException(nameof(company));
            }

            searchModel.CompanyId = company.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Пример #3
0
        public virtual async Task <CompanyCustomerListModel> PrepareCompanyCustomerListModelAsync(CompanyCustomerSearchModel searchModel, Company company)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (company == null)
            {
                throw new ArgumentNullException(nameof(company));
            }

            //get product categories
            var companyCustomers = await _companyService.GetCompanyCustomersByCompanyIdAsync(company.Id,
                                                                                             showHidden : true,
                                                                                             pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            //prepare grid model
            var model = await new CompanyCustomerListModel().PrepareToGridAsync(searchModel, companyCustomers, () =>
            {
                return(companyCustomers.SelectAwait(async companyCustomer =>
                {
                    //fill in model values from the entity
                    var companyCustomerModel = companyCustomer.ToModel <CompanyCustomerModel>();

                    //fill in additional values (not existing in the entity)
                    companyCustomerModel.CustomerFullName = (await _customerService.GetCustomerFullNameAsync(await _customerService.GetCustomerByIdAsync(companyCustomer.CustomerId)));
                    companyCustomerModel.CustomerId = companyCustomer.CustomerId;
                    companyCustomerModel.Email = (await _customerService.GetCustomerByIdAsync(companyCustomer.CustomerId))?.Email;

                    return companyCustomerModel;
                }));
            });

            return(model);
        }