Example #1
0
        public async Task <IActionResult> AttachDefaultThumbnails()
        {
            int siteId = GetCurrentSiteId();

            string assetPath = Path.Combine(
                Directory.GetParent(_hostingEnvironment.WebRootPath).FullName, "assets");

            assetPath = Path.Combine(assetPath, "thumbnails");

            var layers = await _dynamicAvatarService.GetLayersAsync();

            foreach (var layer in layers)
            {
                if (layer.Name != "Body")
                {
                    var layerAssetPath  = Path.Combine(assetPath, layer.Name);
                    var destinationRoot = Path.Combine($"site{siteId}", "dynamicavatars", $"layer{layer.Id}");
                    var destinationPath = _pathResolver.ResolveContentFilePath(destinationRoot);

                    var items = await _dynamicAvatarService.GetItemsByLayerAsync(layer.Id);

                    foreach (var item in items)
                    {
                        var itemRoot = Path.Combine(destinationRoot, $"item{item.Id}");
                        var itemPath = Path.Combine(destinationPath, $"item{item.Id}");

                        var thumbnailImage = Path.Combine(layerAssetPath, $"{item.Name}.jpg");
                        System.IO.File.Copy(Path.Combine(thumbnailImage),
                                            Path.Combine(itemPath, "Thumbnail.jpg"));

                        item.Thumbnail = Path.Combine(itemRoot, "Thumbnail.jpg");
                        await _dynamicAvatarService.UpdateItemAsync(item);
                    }
                }
            }

            ShowAlertSuccess("Default avatar thumbnails have been successfully added.");
            return(View("Index"));
        }