public async Task <IActionResult> AddNew(GenresDto genresDto) { _dbContext.Connection.Open(); using (var transaction = _dbContext.Connection.BeginTransaction()) { try { _dbContext.Database.UseTransaction(transaction as DbTransaction); bool GenresExists = await _dbContext.Genres.AnyAsync(a => a.Name == genresDto.Name); if (GenresExists) { return(BadRequest(new { msg = "Genres Already Exists" })); } var addGenresQuery = $"INSERT INTO genres(Name) VALUES('{genresDto.Name}');SELECT last_insert_rowid()"; var genresId = await _writeDbConnection.QuerySingleAsync <int>(addGenresQuery, transaction : transaction); if (genresId == 0) { return(BadRequest(new { msg = "Genres could not be inserted" })); } await _dbContext.SaveChangesAsync(default);
public async Task <IActionResult> GetByName([FromBody] GenresDto name) { var genres = await _dbContext.Genres.Where(a => a.Name == name.Name).ToListAsync(); if (genres.Count == 0) { return(NotFound(new { msg = "No Data Found" })); } return(Ok(genres)); }
public void Setup() { dateTimeNow = DateTime.Now; movieDto = new MovieDto() { Dates = new MovieDates() { Maximum = dateTimeNow.ToString(), Minimum = dateTimeNow.ToString() }, Page = 1, TotalPages = 1, TotalResults = 20 }; var movies = new List <MovieResult>(); for (int i = 0; i < 20; i++) { movies.Add(new MovieResult { Id = i, GenreIds = new List <int>() { 1, 2 }, Overview = $"Overview {i}", PosterPath = "PosterPath/", ReleaseDate = dateTimeNow.ToString(), Title = "Title" }); } movieDto.Results = movies; genresDto = new GenresDto() { Genres = new List <GenreDto>() { new GenreDto { Id = 1, Name = "Genre1" }, new GenreDto { Id = 2, Name = "Genre2" } } }; }
public GenreModule(SpotifyGenreConnection spotifyGenreConnection) : base("v1/music/genre") { Get("{genreId}", async parameters => await spotifyGenreConnection.GetGenres(parameters.genreId)); Get("{genreId}/playlists", async parameters => await spotifyGenreConnection.GetGenrePlaylist(parameters.genreId)); Get("/", async parameters => { GenresDto genresdto = await spotifyGenreConnection.GetGenres(); Response rep = Response.AsJson(genresdto); rep.ContentType = "application/json"; return(rep); }); }
Movie MapDtoToModel(GenresDto genres, MovieResult movieDto) { return(new Movie() { Id = movieDto.Id, Title = movieDto.Title, PosterSmall = string .Concat(BaseUrl, SmallPosterSize, movieDto.PosterPath), PosterBig = string .Concat(BaseUrl, BigPosterSize, movieDto.PosterPath), Genres = genres.Genres.Where(g => movieDto.GenreIds.Contains(g.Id)).Select(j => j.Name).ToList(), ReleaseDate = DateTime.Parse(movieDto.ReleaseDate, new CultureInfo(Language)), Overview = movieDto.Overview }); }
public async Task <GenresDto> GetGenres() { Uri GenresUrl = new Uri($"https://api.spotify.com/v1/browse/categories"); HttpResponseMessage response = await client.GetAsync(GenresUrl); GenresDto result = JsonConvert.DeserializeObject <GenresDto>(await response.Content.ReadAsStringAsync()); result.categories.items = result.categories.items.Select(item => { item.icons = item.icons.Select(icon => { if (!icon.height.HasValue || !icon.width.HasValue) { icon.height = 274; icon.width = 274; } return(icon); }).ToList(); return(item); }).ToList(); return(result); }