protected virtual async Task <bool> IsAssetCategoryInfoValidAsync(CreateOrderLineDto orderLine, OrderCreationResource resource) { var mapping = (await _grantedStoreAppService.GetListAsync(new GetGrantedStoreListDto { MaxResultCount = 1, StoreId = resource.Input.StoreId, AssetCategoryId = orderLine.GetBookingAssetCategoryId() })).Items.FirstOrDefault(); if (mapping is null) { mapping = (await _grantedStoreAppService.GetListAsync(new GetGrantedStoreListDto { MaxResultCount = 1, AllowAll = true })).Items.FirstOrDefault(); } if (mapping is null) { return(false); } var productAssetCategory = (await _productAssetCategoryAppService.GetListAsync( new GetProductAssetCategoryListDto { MaxResultCount = 1, StoreId = resource.Input.StoreId, ProductId = orderLine.ProductId, ProductSkuId = orderLine.ProductSkuId, AssetCategoryId = orderLine.GetBookingAssetCategoryId(), PeriodSchemeId = orderLine.GetBookingPeriodSchemeId() } )).Items.FirstOrDefault(); return(productAssetCategory is not null); }
protected override async Task HandleOrderCreationAsync(AuthorizationHandlerContext context, OrderOperationAuthorizationRequirement requirement, OrderCreationResource resource) { var productGroupNames = (await _definitionAppService.GetListAsync()).Items.Select(x => x.ProductGroupName); var bookingOrderLines = resource.Input.OrderLines.Where(x => productGroupNames.Contains(resource.ProductDictionary[x.ProductId].ProductGroupName)).ToList(); if (!bookingOrderLines.Any()) { return; } var models = new List <OccupyAssetInfoModel>(); var byCategoryModels = new List <OccupyAssetByCategoryInfoModel>(); foreach (var orderLine in bookingOrderLines) { if (!await IsPeriodInfoValidAsync(orderLine)) { context.Fail(); return; } var assetId = orderLine.FindBookingAssetId(); var assetCategoryId = orderLine.FindBookingAssetCategoryId(); if (assetId is not null) { if (!await IsAssetInfoValidAsync(orderLine, resource)) { context.Fail(); return; } models.Add(CreateOccupyAssetInfoModel(assetId.Value, orderLine)); } else if (assetCategoryId is not null) { if (!await IsAssetCategoryInfoValidAsync(orderLine, resource)) { context.Fail(); return; } byCategoryModels.Add(CreateOccupyAssetByCategoryInfoModel(assetCategoryId.Value, orderLine)); } else { context.Fail(); return; } } try { await _assetOccupancyAppService.CheckBulkCreateAsync(new BulkCreateAssetOccupancyDto { OccupierUserId = Check.NotNull(context.User.FindUserId(), "CurrentUserId"), Models = models, ByCategoryModels = byCategoryModels }); } catch { context.Fail(); return; } }