Exemplo n.º 1
0
        protected async Task AddSelectionToCollection()
        {
            var parameters = new DialogParameters
            {
                { "EntityType", _selectedItems.Count.ToString() }, { "EntityName", "selected items" }
            };
            var options = new DialogOptions {
                CloseButton = true, MaxWidth = MaxWidth.ExtraSmall
            };

            IDialogReference dialog = Dialog.Show <AddToCollectionDialog>("Add To Collection", parameters, options);
            DialogResult     result = await dialog.Result;

            if (!result.Cancelled && result.Data is MediaCollectionViewModel collection)
            {
                var request = new AddItemsToCollection(
                    collection.Id,
                    _selectedItems.OfType <MovieCardViewModel>().Map(m => m.MovieId).ToList(),
                    _selectedItems.OfType <TelevisionShowCardViewModel>().Map(s => s.TelevisionShowId).ToList());

                Either <BaseError, Unit> addResult = await Mediator.Send(request);

                addResult.Match(
                    Left: error =>
                {
                    Snackbar.Add($"Unexpected error adding items to collection: {error.Value}");
                    Logger.LogError("Unexpected error adding items to collection: {Error}", error.Value);
                },
                    Right: _ =>
                {
                    Snackbar.Add(
                        $"Added {_selectedItems.Count} items to collection {collection.Name}",
                        Severity.Success);
                    ClearSelection();
                });
            }
        }