Exemplo n.º 1
0
        // ShareAlbum <albumId> <username> <permission>
        // For example:
        // ShareAlbum 4 dragon321 Owner
        // ShareAlbum 4 dragon11 Viewer
        public string Execute(string[] data)
        {
            int    albumId    = int.Parse(data[0]);
            string username   = data[1];
            string permission = data[2];

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

            if (!userService.Exists(username))
            {
                return(String.Format(UserNotFound, username));
            }

            if (!albumService.Exists(albumId))
            {
                return(String.Format(AlbumNotFound, albumId));
            }

            var user  = userService.ByUsername <User>(username);
            var album = albumService.ById <Album>(albumId);

            try
            {
                albumRoleService.PublishAlbumRole(albumId, user.Id, permission);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(String.Format(SuccessMessage, username, album.Name, permission));
        }
Exemplo n.º 2
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));
        }
        // UploadPicture <albumName> <pictureTitle> <pictureFilePath>
        public string Execute(string[] data)
        {
            string albumName    = data[0];
            string pictureTitle = data[1];
            string path         = data[2];

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

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

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

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

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

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