Exemple #1
0
        /// <summary>
        /// Get group breadcrumb
        /// </summary>
        /// <param name="group">MaterialGroup</param>
        /// <param name="materialGroupService">MaterialGroup service</param>
        /// <param name="aclService">ACL service</param>
        /// <param name="storeMappingService">Store mapping service</param>
        /// <param name="showHidden">A value indicating whether to load hidden records</param>
        /// <returns>MaterialGroup breadcrumb </returns>
        public static IList <MaterialGroup> GetMaterialGroupBreadCrumb(this MaterialGroup group,
                                                                       IMaterialGroupService materialGroupService,
                                                                       IAclService aclService,
                                                                       IStoreMappingService storeMappingService,
                                                                       bool showHidden = false)
        {
            if (group == null)
            {
                throw new ArgumentNullException(nameof(group));
            }

            var result = new List <MaterialGroup>();

            //used to prevent circular references
            var alreadyProcessedMaterialGroupIds = new List <int>();

            while (group != null &&  //not null
                   !group.Deleted && //not deleted
                   //(showHidden || aclService.Authorize(group)) && //ACL
                   //(showHidden || storeMappingService.Authorize(group)) && //Store mapping
                   !alreadyProcessedMaterialGroupIds.Contains(group.Id)) //prevent circular references
            {
                result.Add(group);

                alreadyProcessedMaterialGroupIds.Add(group.Id);

                group = materialGroupService.GetMaterialGroupById(group.ParentGroupId);
            }
            result.Reverse();
            return(result);
        }
        public virtual IActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(XrmsPermissionProvider.ManageMaterialGroups))
            {
                return(AccessDeniedView());
            }

            var materialGroup = _materialGroupService.GetMaterialGroupById(id);

            if (materialGroup == null || materialGroup.Deleted)
            {
                //No group found with the specified id
                return(RedirectToAction("List"));
            }

            var viewModel = materialGroup.ToDetailsViewModel();

            // prepare parent groups
            PrepareAvailableMaterialGroups(viewModel);

            return(View("~/Plugins/Xrms.MaterialAdmin/Areas/Admin/Views/MaterialGroup/Edit.cshtml", viewModel));
        }
        public virtual IActionResult SearchMaterials(DataSourceRequest command, AddProductRecipesPopupViewModel.SearchMaterialsModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedKendoGridJson());
            }

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

            var groupIds = new List <int> {
                model.SearchMaterialGroupId
            };

            // include sub groups
            if (model.SearchIncludeSubGroup && model.SearchMaterialGroupId > 0)
            {
                groupIds.AddRange(GetChildGroupIds(model.SearchMaterialGroupId));
            }

            var materials = _materialService.SearchMaterials(
                groupIds: groupIds,
                warehouseId: model.SearchWarehouseId,
                keywords: model.SearchMaterialName,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                showHidden: true
                );
            var gridModel = new DataSourceResult
            {
                Data = materials.Select(x =>
                {
                    var materialModel = new
                    {
                        Id = x.Id,
                        PictureThumbnailUrl = _pictureService.GetPictureUrl(x.PictureId, 75, true),
                        Name  = x.Name,
                        Unit  = x.Unit,
                        Group = _materialGroupService.GetMaterialGroupById(x.MaterialGroupId).GetFormattedBreadCrumb(_materialGroupService)
                    };

                    return(materialModel);
                }),
                Total = materials.TotalCount
            };

            return(Json(gridModel));
        }
Exemple #4
0
        public virtual IActionResult List(DataSourceRequest command, SearchMaterialsModel model)
        {
            if (!_permissionService.Authorize(XrmsPermissionProvider.ManageMaterials))
            {
                return(AccessDeniedKendoGridJson());
            }

            var categoryIds = new List <int> {
                model.SearchMaterialGroupId
            };

            // include sub group
            if (model.SearchIncludeSubGroup && model.SearchMaterialGroupId > 0)
            {
                categoryIds.AddRange(GetChildGroupIds(model.SearchMaterialGroupId));
            }

            var materials = _materialService.SearchMaterials(
                groupIds: categoryIds,
                warehouseId: model.SearchWarehouseId,
                keywords: model.SearchMaterialName,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                showHidden: true
                );
            var gridModel = new DataSourceResult
            {
                Data = materials.Select(x =>
                {
                    var materialModel = x.ToListItemViewModel();

                    // group
                    materialModel.Group = _materialGroupService.GetMaterialGroupById(x.MaterialGroupId).GetFormattedBreadCrumb(_materialGroupService);

                    // picture
                    materialModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(x.PictureId, 75, true);

                    return(materialModel);
                }),
                Total = materials.TotalCount
            };

            return(Json(gridModel));
        }