Example #1
0
        public async Task <IActionResult> AddSitemapItems(string sitemapId, [FromBody] SitemapItem[] items)
        {
            if (string.IsNullOrEmpty(sitemapId))
            {
                return(BadRequest("sitemapId is null"));
            }
            if (items == null)
            {
                return(BadRequest("items is null"));
            }

            foreach (var item in items)
            {
                item.SitemapId = sitemapId;
            }
            await _sitemapItemService.SaveChangesAsync(items);

            return(Ok());
        }
        public async Task DoImportAsync(Stream inputStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo();

            using (var streamReader = new StreamReader(inputStream))
                using (var reader = new JsonTextReader(streamReader))
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            if (reader.Value.ToString() == "Sitemaps")
                            {
                                await reader.DeserializeJsonArrayWithPagingAsync <Sitemap>(_jsonSerializer, _batchSize, items => _sitemapService.SaveChangesAsync(items.ToArray()), processedCount =>
                                {
                                    progressInfo.Description = $"{ processedCount } site maps have been imported";
                                    progressCallback(progressInfo);
                                }, cancellationToken);
                            }
                            else if (reader.Value.ToString() == "SitemapItems")
                            {
                                await reader.DeserializeJsonArrayWithPagingAsync <SitemapItem>(_jsonSerializer, _batchSize, items => _sitemapItemService.SaveChangesAsync(items.ToArray()), processedCount =>
                                {
                                    progressInfo.Description = $"{ processedCount } site maps items have been imported";
                                    progressCallback(progressInfo);
                                }, cancellationToken);
                            }
                        }
                    }
                }
        }