public async Task <ActionResult> BulkCreateLinks([FromBody] BulkLinkCreationRequest creationRequest) { if (creationRequest.CatalogId.IsNullOrEmpty() || creationRequest.CategoryId.IsNullOrEmpty()) { return(BadRequest("Target catalog and category identifiers should be specified.")); } var searchCriteria = creationRequest.SearchCriteria; bool haveProducts; do { var links = new List <IHasLinks>(); var searchResult = await _listEntrySearchService.SearchAsync(searchCriteria); var hasLinksEntities = await LoadCatalogEntriesAsync <IHasLinks>(searchResult.ListEntries.Select(x => x.Id).ToArray()); haveProducts = hasLinksEntities.Any(); searchCriteria.Skip += searchCriteria.Take; //CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, links.ToArray()); if (haveProducts) { await SaveListCatalogEntitiesAsync(hasLinksEntities.ToArray()); } } while (haveProducts); return(NoContent()); }
public async Task <ActionResult> BulkCreateLinks([FromBody] BulkLinkCreationRequest creationRequest) { if (creationRequest.CatalogId.IsNullOrEmpty()) { return(BadRequest("Target catalog identifier should be specified.")); } var searchCriteria = creationRequest.SearchCriteria; bool haveProducts; do { var searchResult = await _listEntrySearchService.SearchAsync(searchCriteria); var hasLinkEntries = await LoadCatalogEntriesAsync <IHasLinks>(searchResult.ListEntries.Select(x => x.Id).ToArray()); haveProducts = hasLinkEntries.Any(); searchCriteria.Skip += searchCriteria.Take; var authorizationResult = await _authorizationService.AuthorizeAsync(User, hasLinkEntries, new CatalogAuthorizationRequirement(ModuleConstants.Security.Permissions.Update)); if (!authorizationResult.Succeeded) { return(Unauthorized()); } foreach (var hasLinkEntry in hasLinkEntries) { var link = AbstractTypeFactory <CategoryLink> .TryCreateInstance(); link.CategoryId = creationRequest.CategoryId; link.CatalogId = creationRequest.CatalogId; hasLinkEntry.Links.Add(link); } if (haveProducts) { await SaveListCatalogEntitiesAsync(hasLinkEntries.ToArray()); } } while (haveProducts); return(Ok()); }