Ejemplo n.º 1
0
        public virtual IActionResult AffiliatedCustomerList(AffiliatedCustomerSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates))
            {
                return(AccessDeniedKendoGridJson());
            }

            //try to get an affiliate with the specified id
            var affiliate = _affiliateService.GetAffiliateById(searchModel.AffliateId)
                            ?? throw new ArgumentException("No affiliate found with the specified id");

            //prepare model
            var model = _affiliateModelFactory.PrepareAffiliatedCustomerListModel(searchModel, affiliate);

            return(Json(model));
        }
        public virtual async Task <IActionResult> AffiliatedCustomerList(AffiliatedCustomerSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAffiliates))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get an affiliate with the specified id
            var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId)
                            ?? throw new ArgumentException("No affiliate found with the specified id");

            //prepare model
            var model = await _affiliateModelFactory.PrepareAffiliatedCustomerListModelAsync(searchModel, affiliate);

            return(Json(model));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Prepare paged affiliated customer list model
        /// </summary>
        /// <param name="searchModel">Affiliated customer search model</param>
        /// <param name="affiliate">Affiliate</param>
        /// <returns>Affiliated customer list model</returns>
        public virtual AffiliatedCustomerListModel PrepareAffiliatedCustomerListModel(AffiliatedCustomerSearchModel searchModel,
                                                                                      Affiliate affiliate)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get customers
            var customers = _customerService.GetAllCustomers(affiliateId: affiliate.Id,
                                                             pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new AffiliatedCustomerListModel
            {
                //fill in model values from the entity
                Data = customers.Select(customer => new AffiliatedCustomerModel
                {
                    Id   = customer.Id,
                    Name = customer.Email
                }),
                Total = customers.TotalCount
            };

            return(model);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Prepare affiliated customer search model
        /// </summary>
        /// <param name="searchModel">Affiliated customer search model</param>
        /// <param name="affiliate">Affiliate</param>
        /// <returns>Affiliated customer search model</returns>
        protected virtual AffiliatedCustomerSearchModel PrepareAffiliatedCustomerSearchModel(AffiliatedCustomerSearchModel searchModel, Affiliate affiliate)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            searchModel.AffliateId = affiliate.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Prepare paged affiliated customer list model
        /// </summary>
        /// <param name="searchModel">Affiliated customer search model</param>
        /// <param name="affiliate">Affiliate</param>
        /// <returns>Affiliated customer list model</returns>
        public virtual AffiliatedCustomerListModel PrepareAffiliatedCustomerListModel(AffiliatedCustomerSearchModel searchModel,
                                                                                      Affiliate affiliate)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get customers
            var customers = _customerService.GetAllCustomers(affiliateId: affiliate.Id,
                                                             pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new AffiliatedCustomerListModel().PrepareToGrid(searchModel, customers, () =>
            {
                //fill in model values from the entity
                return(customers.Select(customer =>
                {
                    var affiliatedCustomerModel = customer.ToModel <AffiliatedCustomerModel>();
                    affiliatedCustomerModel.Name = customer.Email;

                    return affiliatedCustomerModel;
                }));
            });

            return(model);
        }