public async Task InsertFilmPosterAsync(FilmPosterModel imageModel) { string filmPosterPath = _configuration.GetSection("FilmPostersPath").Value; FilmPosterEntity result = await _filmRepository.GetFilmPosterAsync(imageModel.FilmId); if (result.PosterUniqueId != null) { File.Delete(Path.Combine(filmPosterPath, result.PosterUniqueId)); } string posterUniqueId = Guid.NewGuid().ToString(); string posterExtension = Path.GetExtension(imageModel.FormFile.FileName); string path = Path.Combine(filmPosterPath, posterUniqueId + posterExtension); if (imageModel.FormFile != null && imageModel.FormFile.Length > 0) { using (FileStream stream = new FileStream(path, FileMode.Create)) { await imageModel.FormFile.CopyToAsync(stream); } } await _filmRepository.InsertFilmPosterAsync( new FilmPosterEntity( imageModel.FilmId, posterUniqueId, posterExtension ) ); }
public async Task InsertFilmPosterAsync(FilmPosterEntity filmPosterEntity) { using (IDbConnection dbConnection = new SqlConnection(_settings.ConnectionString)) { await dbConnection.QuerySingleOrDefaultAsync <int>( "InsertFilmPoster", filmPosterEntity, commandType : CommandType.StoredProcedure ); } }
public async Task <FilmPosterEntity> GetFilmPosterAsync(int id) { using (IDbConnection dbConnection = new SqlConnection(_settings.ConnectionString)) { FilmPosterEntity filmPoster = await dbConnection.QuerySingleOrDefaultAsync <FilmPosterEntity>( "GetFilmPoster", new { Id = id }, commandType : CommandType.StoredProcedure ); return(filmPoster); } }