Ejemplo n.º 1
0
        public async Task <IActionResult> GroupOutletList(GroupOutletSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageOutletManagement))
            {
                return(AccessDeniedKendoGridJson());
            }

            var model = await _managementModelFactory.PrepareGroupOutletListModel(searchModel);

            return(Json(model));
        }
Ejemplo n.º 2
0
        public async Task <GroupOutletListModel> PrepareGroupOutletListModel(GroupOutletSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            var groupList = await _outletManagementService.GetGroupOutletsAsync();

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

            var model = new GroupOutletListModel
            {
                //Data = groupList.PaginationByRequestModel(searchModel).Select(groupOutlet =>
                Data = groupList.Select(groupOutlet =>
                {
                    var groupOutletsModel              = groupOutlet.ToModel <GroupOutletModel>();
                    groupOutletsModel.GroupName        = groupOutlet.GroupName;
                    groupOutletsModel.StoreName        = String.Join(", ", groupOutlet.Store.Select(store => store.P_BranchNo + " - " + store.P_Name)); // get from store table
                    groupOutletsModel.CreatedOn        = _dateTimeHelper.ConvertToUserTime(groupOutlet.CreatedOnUtc, DateTimeKind.Utc);
                    groupOutletsModel.LastActivityDate = _dateTimeHelper.ConvertToUserTime(groupOutlet.ModifiedOnUtc.GetValueOrDefault(DateTime.UtcNow), DateTimeKind.Utc);

                    return(groupOutletsModel);
                }),
                Total = groupList.Count
            };

            // sort
            if (searchModel.Sort != null && searchModel.Sort.Any())
            {
                foreach (var s in searchModel.Sort)
                {
                    model.Data = await model.Data.Sort(s.Field, s.Dir);
                }
            }

            // filter
            if (searchModel.Filter != null && searchModel.Filter.Filters != null && searchModel.Filter.Filters.Any())
            {
                var filter = searchModel.Filter;
                model.Data = await model.Data.Filter(filter);

                model.Total = model.Data.Count();
            }

            return(model);
        }