コード例 #1
0
        public async Task <int> Handle(CreateAlbumCommand request, CancellationToken cancellationToken)
        {
            var albumModel = request.Album;

            if (albumModel == null)
            {
                throw new Exception("Album doesn't exists!");
            }

            var imageGuidUrl = await _imageWriter.UploadImage(albumModel.Cover);

            var album = new Album
            {
                Name      = albumModel.Name,
                Created   = DateTimeOffset.Now,
                CreatedBy = request.UserId,
                CoverUrl  = imageGuidUrl
            };

            AttachAuthor(albumModel, album);

            album.UserId = request.UserId;

            _context.Album.Add(album);

            await _context.SaveChangesAsync(cancellationToken);

            return(album.Id);
        }
コード例 #2
0
        public async Task <int> Handle(CreatePlaylistCommand request, CancellationToken cancellationToken)
        {
            var playlistModel = request.Playlist;

            if (playlistModel == null)
            {
                throw new Exception("Playlist doesn't exists!");
            }

            var imageGuidUrl = await _imageWriter.UploadImage(playlistModel.Cover);

            var playlist = new Playlist
            {
                Name      = playlistModel.Name,
                Created   = DateTimeOffset.Now,
                CreatedBy = request.UserId,
                CoverUrl  = imageGuidUrl
            };

            playlist.UserId = request.UserId;

            _context.Playlist.Add(playlist);

            await _context.SaveChangesAsync(cancellationToken);

            return(playlist.Id);
        }
コード例 #3
0
        public async Task <IActionResult> UploadImage(IFormFile file)
        {
            try
            {
                var writter = new ImageWriter();
                var upload  = await writter.UploadImage(file);

                //await _userService.EditProfile(new UserModel { ProfilePicUrl = upload });
                var path = Path.Combine("images", upload);
                //return Ok(new { ProfilePictureUrl = upload });
                return(Ok(path));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
コード例 #4
0
        public async Task <int> Handle(CreateSongToPlaylistCommand request, CancellationToken cancellationToken)
        {
            var songModel = request.Song;

            if (songModel == null)
            {
                throw new Exception("Song doesn't exists!");
            }

            var playlist = _context.Playlist.Find(request.PlaylistId);

            if (playlist == null)
            {
                throw new Exception("Playlist doesn't exists!");
            }

            //TO DO: Add more validation for song size, cover size, format, etc.
            var imageGuidUrl = await _imageWriter.UploadImage(songModel.Cover);

            var songGuidUrl = await _audioWriter.UploadAudio(songModel.Audio);

            var song = new Song
            {
                Name      = songModel.Name,
                Playlist  = playlist,
                Created   = DateTimeOffset.Now,
                CreatedBy = request.UserId,
                CoverUrl  = imageGuidUrl,
                AudioUrl  = songGuidUrl
            };

            AttachAuthor(request, song);

            _context.Song.Add(song);

            await _context.SaveChangesAsync(cancellationToken);

            return(song.Id);
        }