コード例 #1
0
ファイル: ArtistManager.cs プロジェクト: yasinfmd/musicApi
        public async Task <BaseResponse <FilesDto> > UpdateArtistProfileImage(UpdateProfilePhoto artistPhoto)
        {
            BaseResponse <FilesDto> baseResponse = new BaseResponse <FilesDto>();
            var artist = await GetByID(artistPhoto.Id);

            if (artist.Result != null)
            {
                var file = await _filesService.GetByID(artist.Result.File.Id);

                if (file.Result != null)
                {
                    string   pathBuild = Path.Combine(Directory.GetCurrentDirectory(), "Uploads\\");
                    string[] fileName  = artist.Result.File.Path.Split("Uploads/");
                    pathBuild = Path.Combine(pathBuild, fileName[fileName.Length - 1]);
                    var deletedFileFromStorage = _filesService.DeleteFile(pathBuild);
                    var newFile = await _filesService.UploadFileFromStorage(new Files { ImageFile = artistPhoto.File });

                    file.Result.Path = _configuration["FilePath"] + newFile;
                    file.Result.Name = artistPhoto.File.FileName;
                    file.Result.Size = Convert.ToInt32(artistPhoto.File.Length);
                    var updatedFile = await _filesService.Update(file.Result);

                    baseResponse.Result = updatedFile.Result;
                    //"http://localhost:5000/" + "Uploads/"
                }
            }
            return(baseResponse);
        }
コード例 #2
0
 public async Task <IActionResult> updateArtistPhoto([FromForm] UpdateProfilePhoto updateProfilePhoto)
 {
     try
     {
         InfoLog(ControllerContext.ActionDescriptor.DisplayName);
         return(Ok(await _artistService.UpdateArtistProfileImage(updateProfilePhoto)));
     }
     catch (Exception exception)
     {
         return(ErrorInternal(exception, $"{ControllerContext.ActionDescriptor.DisplayName} Exception Message : {exception.Message} - {exception.InnerException}"));
     }
 }