Beispiel #1
0
        public async Task <IActionResult> addAlbumPhotos([FromForm] AlbumArtistPhotosModel albumArtistPhotosModel)
        {
            try
            {
                InfoLog(ControllerContext.ActionDescriptor.DisplayName);
                if (ModelState.IsValid)
                {
                    var result = await _albumService.AddAlbumPhotos(albumArtistPhotosModel);

                    InfoLog($"Resim Eklendi {result}");
                    return(Ok(result));
                }
                return(BadRequest());
            }
            catch (Exception exception)
            {
                return(ErrorInternal(exception, $"{ControllerContext.ActionDescriptor.DisplayName} Exception Message : {exception.Message} - {exception.InnerException}"));
            }
        }
Beispiel #2
0
        public async Task <BaseResponse <List <AlbumFilesDto> > > AddAlbumPhotos(AlbumArtistPhotosModel albumArtistPhotosModel)
        {
            BaseResponse <List <AlbumFilesDto> > baseResponse = new BaseResponse <List <AlbumFilesDto> >();
            var album = await _albumRepository.FindOne(x => x.Id == albumArtistPhotosModel.AlbumId);

            List <AlbumsFiles> albumsFiles = new List <AlbumsFiles>();

            foreach (var item in albumArtistPhotosModel.Files)
            {
                Files  f        = new Files();
                string path     = _helper.UploadStorage(item.Name, item.FileName);
                string fileName = Path.GetFileNameWithoutExtension(item.Name);
                // string extension = Path.GetExtension(item.FileName);
                //fileName = fileName + "_" + Guid.NewGuid().ToString() + extension;
                // string pathBuild = Path.Combine(Directory.GetCurrentDirectory(), "Uploads\\");
                // string path = Path.Combine(Directory.GetCurrentDirectory(), "Uploads\\", fileName);
                using (var FileStream = new FileStream(path, FileMode.Create))
                {
                    await item.CopyToAsync(FileStream);
                }
                f.Name = item.FileName;
                f.Size = Convert.ToInt32(item.Length);
                //"http://localhost:5000/Uploads/"
                f.Path = _configuration["FilePath"] + fileName;
                albumsFiles.Add(new AlbumsFiles {
                    Album = album, File = f
                });
            }
            album.AlbumsFiles = albumsFiles;
            var updatedAlbum = await _albumRepository.Update(album);

            var albumFileDto = _mapper.Map <List <AlbumFilesDto> >(updatedAlbum.AlbumsFiles);

            baseResponse.Result = albumFileDto;
            return(baseResponse);
            // album
            // throw new NotImplementedException();
        }