Exemplo n.º 1
0
        public object DeleteAuthor([FromBody] AuthorEditorResource resource)
        {
            foreach (var authorId in resource.AuthorIds)
            {
                _authorService.DeleteAuthor(authorId, false);
            }

            return(new object());
        }
Exemplo n.º 2
0
        public IActionResult SaveAll([FromBody] AuthorEditorResource resource)
        {
            var authorsToUpdate = _authorService.GetAuthors(resource.AuthorIds);
            var authorsToMove   = new List <BulkMoveAuthor>();

            foreach (var author in authorsToUpdate)
            {
                if (resource.Monitored.HasValue)
                {
                    author.Monitored = resource.Monitored.Value;
                }

                if (resource.QualityProfileId.HasValue)
                {
                    author.QualityProfileId = resource.QualityProfileId.Value;
                }

                if (resource.MetadataProfileId.HasValue)
                {
                    author.MetadataProfileId = resource.MetadataProfileId.Value;
                }

                if (resource.RootFolderPath.IsNotNullOrWhiteSpace())
                {
                    author.RootFolderPath = resource.RootFolderPath;
                    authorsToMove.Add(new BulkMoveAuthor
                    {
                        AuthorId   = author.Id,
                        SourcePath = author.Path
                    });
                }

                if (resource.Tags != null)
                {
                    var newTags   = resource.Tags;
                    var applyTags = resource.ApplyTags;

                    switch (applyTags)
                    {
                    case ApplyTags.Add:
                        newTags.ForEach(t => author.Tags.Add(t));
                        break;

                    case ApplyTags.Remove:
                        newTags.ForEach(t => author.Tags.Remove(t));
                        break;

                    case ApplyTags.Replace:
                        author.Tags = new HashSet <int>(newTags);
                        break;
                    }
                }
            }

            if (resource.MoveFiles && authorsToMove.Any())
            {
                _commandQueueManager.Push(new BulkMoveAuthorCommand
                {
                    DestinationRootFolder = resource.RootFolderPath,
                    Author = authorsToMove
                });
            }

            return(Accepted(_authorService.UpdateAuthors(authorsToUpdate, !resource.MoveFiles).ToResource()));
        }