public virtual async Task <IActionResult> CustomerAddPopupList(AddCustomerToCompanySearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories)) { return(await AccessDeniedDataTablesJson()); } //prepare model var model = await _companyModelFactory.PrepareAddCustomerToCompanyListModelAsync(searchModel); return(Json(model)); }
public virtual async Task <IActionResult> CustomerAddPopup(int companyId) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories)) { return(AccessDeniedView()); } var searchModel = new AddCustomerToCompanySearchModel(); searchModel.CompanyId = companyId; //prepare model var model = await _companyModelFactory.PrepareAddCustomerToCompanySearchModelAsync(searchModel); return(View(model)); }
public virtual async Task <AddCustomerToCompanyListModel> PrepareAddCustomerToCompanyListModelAsync(AddCustomerToCompanySearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var customerRoleIds = new[] { (await _customerService.GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.RegisteredRoleName)).Id }; //get customers var customers = await _customerService.GetAllCustomersAsync( email : searchModel.SearchCustomerEmail, customerRoleIds : customerRoleIds, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); IPagedList <Customer> filteredCustomers = new PagedList <Customer>(new List <Customer>(), searchModel.Page - 1, searchModel.PageSize, customers.TotalCount); foreach (var customer in customers) { var companyCustomerMapping = await _companyService.GetCompanyCustomersByCustomerIdAsync(customer.Id); if (companyCustomerMapping.Count == 0) { filteredCustomers.Add(customer); } } //prepare grid model var model = await new AddCustomerToCompanyListModel().PrepareToGridAsync(searchModel, filteredCustomers, () => { return(filteredCustomers.SelectAwait(async customer => { var customerModel = customer.ToModel <CustomerModel>(); customerModel.FullName = (await _customerService.GetCustomerFullNameAsync(await _customerService.GetCustomerByIdAsync(customer.Id))); customerModel.Id = customer.Id; customerModel.Active = customer.Active; customerModel.Email = (await _customerService.GetCustomerByIdAsync(customer.Id))?.Email; return customerModel; })); }); return(model); }
public virtual async Task <AddCustomerToCompanySearchModel> PrepareAddCustomerToCompanySearchModelAsync(AddCustomerToCompanySearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var customer = await _workContext.GetCurrentCustomerAsync(); //prepare page parameters searchModel.SetPopupGridPageSize(); return(searchModel); }