// 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);
        }
Exemple #2
0
        // ShareAlbum <albumId> <username> <permission>
        public string Execute(string[] data)
        {
            int      albumId  = int.Parse(data[0]);
            AlbumDto albumDTO = albumService.ById <AlbumDto>(albumId);

            if (albumDTO == null)
            {
                throw new ObjectNotFoundException(typeof(Album).Name, data[0]);
            }
            string       username = data[1];
            UserRolesDto userDTO  = userService.ByUsername <UserRolesDto>(username);

            if (userDTO == null || userDTO.IsDeleted == true)
            {
                throw new ObjectNotFoundException(typeof(User).Name, username);
            }
            if (!Enum.TryParse(data[2], true, out Role role))
            {
                throw new InvalidPermissionException();
            }
            string       permission         = role.ToString();
            AlbumRoleDto alreadySharedAlbum = userDTO.Permissions
                                              .FirstOrDefault(p => p.AlbumName == albumDTO.Name);

            if (alreadySharedAlbum != null && alreadySharedAlbum.Permission == permission)
            {
                throw new PermissionAlreadyGrantedException(username, permission, albumDTO.Name);
            }
            AlbumRole albumRole = albumRoleService.PublishAlbumRole(albumId, userDTO.Id, permission);

            return(String.Format(SuccessMessage, username, albumDTO.Name, permission));
        }
        // UploadPicture <albumName> <pictureTitle> <pictureFilePath>
        public string Execute(string[] data)
        {
            string albumName    = data[0];
            string pictureTitle = data[1];
            string path         = data[2];

            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!");
            }

            var albumExists = this.albumService.Exists(albumName);

            if (!albumExists)
            {
                throw new ArgumentException($"Album {albumName} not found!");
            }

            var albumId = this.albumService.ByName <AlbumDto>(albumName).Id;

            var picture = this.pictureService.Create(albumId, pictureTitle, path);

            return($"Picture {pictureTitle} added to {albumName}!");
        }