public string Execute(string[] args)
        {
            string albumName = args[0];
            string tag       = args[1];

            tag = tag.ValidateOrTransform();

            bool isAlbumExist = albumService.Exists(albumName);
            bool isTagExist   = tagService.Exists(tag);

            if (!isAlbumExist || !isTagExist)
            {
                throw new ArgumentException("Either tag or album do not exist!");
            }

            int albumId = albumService.ByName <Album>(albumName).Id;
            int tagId   = tagService.ByName <Tag>(tag).Id;

            bool isTadgAdded = albumTagService.Exists(albumId, tagId);

            if (isTadgAdded)
            {
                throw new ArgumentException($"Tag {tag} is already added to album {albumName}!");
            }

            albumTagService.AddTagTo(albumId, tagId);

            return($"Tag {tag} added to {albumName}!");
        }
        // AddTagTo <albumName> <tag>
        public string Execute(string[] args)
        {
            var albumName = args[0];
            var tag       = args[1];

            if (!userSessionService.IsLoggedIn())
            {
                throw new InvalidOperationException("Invalid credentials!");
            }
            var          username = userSessionService.User.Username;
            AlbumRoleDto roleDto  = albumRoleService.GetAlbumOwner <AlbumRoleDto>(albumName, username);

            if (roleDto == null)
            {
                throw new InvalidOperationException("Invalid credentials!");
            }
            if (tagService.Exists(tag) == false && albumService.Exists(albumName))
            {
                throw new ArgumentException("Either tag or album do not exist!");
            }
            var tagDto   = tagService.ByName <TagDto>(tag);
            var albumDto = albumService.ByName <AlbumDto>(albumName);

            albumTagService.AddTagTo(albumDto.Id, tagDto.Id);

            var result = $"Tag {tag} added to {albumName}!";

            return(result);
        }
Exemplo n.º 3
0
        // AddTagTo <albumName> <tag>
        public string Execute(string[] args)
        {
            var albumName = args[0];
            var tagName   = Utilities.TagUtilities.ValidateOrTransform(args[1]);

            if (!albumService.Exists(albumName) || !tagService.Exists(tagName))
            {
                return(TagOrAlbumNotExist);
            }

            var album = albumService.ByName <Album>(albumName);
            var tag   = tagService.ByName <Tag>(tagName);

            if (albumRoleService.GetOwnerId(album.Id) != Session.CurrentUser.Id)
            {
                return(OperationNotAllowed);
            }


            albumTagService.AddTagTo(album.Id, tag.Id);

            return(String.Format(SuccessMessage, tagName, albumName));
        }
        // AddTagTo <albumName> <tag>
        public string Execute(string[] data)
        {
            string       albumName = data[0];
            AlbumTagsDto albumDTO  = albumService.ByName <AlbumTagsDto>(albumName);

            if (albumDTO == null)
            {
                throw new ObjectNotFoundException(typeof(Album).Name, albumName);
            }
            string tagName = $"#{data[1]}";
            TagDto tagDTO  = tagService.ByName <TagDto>(tagName);

            if (tagDTO == null)
            {
                throw new ObjectNotFoundException(typeof(Tag).Name, tagName);
            }
            if (albumDTO.Tags.Any(t => t.TagName == tagName))
            {
                throw new TagAlreadyAddedException(tagName, albumName);
            }
            AlbumTag albumTag = albumTagService.AddTagTo(albumDTO.Id, tagDTO.Id);

            return(String.Format(SuccessMessage, tagName, albumName));
        }