public bool crearGeneroMusical(GeneroMusical genero) { SqlConnection con = null; SqlCommand cmd = null; bool respuesta = false; try { con = Conexion.getInstance().conexionBd(); cmd = new SqlCommand("BD_CrearGenero", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@prmNombre", genero.nombre); cmd.Parameters.AddWithValue("@prmFoto", genero.imagen); con.Open(); int filas = cmd.ExecuteNonQuery(); if (filas > 0) { respuesta = true; } } catch (Exception ex) { respuesta = false; throw ex; } finally { con.Close(); } return(respuesta); }
private Item GetDiscosSpotifyId(string id, GeneroMusical genero) { Token _token = GetToken(); if (_token == null || string.IsNullOrEmpty(id.ToString())) { return(null); } var requisicaoWeb = WebRequest.CreateHttp($"https://api.spotify.com/v1/albums/{id}"); requisicaoWeb.Method = "GET"; requisicaoWeb.ContentType = "application/x-www-form-urlencoded"; requisicaoWeb.Headers.Add("Authorization", string.Format("{0} {1}", _token.token_type, _token.access_token)); try { using (var resposta = requisicaoWeb.GetResponse()) { if (resposta.ContentLength > 0) { var streamDados = resposta.GetResponseStream(); StreamReader reader = new StreamReader(streamDados); object objResponse = reader.ReadToEnd(); Item post = JsonConvert.DeserializeObject <Item>(objResponse.ToString()); return(post); } } } catch (Exception ex) { } return(null); }
public Disco GetDiscosId(string id, GeneroMusical genero) { Item item = GetDiscosSpotifyId(id, genero); if (item != null) { Disco disco = new Disco(); disco.Id = item.id; disco.Nome = item.name; disco.Ano = item.release_date.Substring(0, 4); disco.href = item.href; disco.Imagem = item.images.Select(s => s.url).Last(); //disco.Preco = CashBack.Preco(genero); //disco.CashBack = CashBack.ValorDia(genero); disco.Genero = genero; return(disco); } else { Disco disco = new Disco { Id = "NãoDefinido" }; //List<Disco> ret = new List<Disco>(); //ret.Add(disco); return(disco); } }
public ActionResult<IEnumerable<Disco>> Get(string g) { g = string.IsNullOrEmpty(g) ? "" : g.ToUpper(); GeneroMusical genero = GeneroMusical.POP; if (g.Contains("POP")) genero = GeneroMusical.POP; else if (g.Contains("MPB")) genero = GeneroMusical.MPB; else if (g.Contains("CLASSIC")) genero = GeneroMusical.CLASSIC; else if (g.Contains("rock")) genero = GeneroMusical.ROCK; else g = "error"; IEnumerable<Disco> lista = null; if (g != "error") lista = _appDisco.GetAll(genero); if (lista == null) { return BadRequest(new { Status = "400", Mensagem = "Genero Inválido" }); } if (lista.Count() > 0) { return Ok(lista); } else { return NotFound(new { Status = "404", Mensagem = "Discos não localizados" }); } }
public void Excluir(int id) { GeneroMusical generoMusicalExcluir = context.GeneroMusicais.First(x => x.generomusical_id == id); context.Set <GeneroMusical>().Remove(generoMusicalExcluir); context.SaveChanges(); }
private static int ValorDia(GeneroMusical generoMusical) { int dia = (int)DateTime.Now.DayOfWeek; int[] pop = { 25, 7, 6, 2, 10, 15, 20 }; int[] mpb = { 30, 5, 10, 15, 20, 25, 30 }; int[] classic = { 35, 3, 5, 8, 13, 18, 25 }; int[] rock = { 40, 10, 15, 15, 15, 20, 40 }; switch (generoMusical) { case GeneroMusical.POP: return(pop[dia]); case GeneroMusical.MPB: return(mpb[dia]); case GeneroMusical.CLASSIC: return(classic[dia]); case GeneroMusical.ROCK: return(rock[dia]); default: return(0); } }
public IEnumerable <Disco> GetAll(GeneroMusical genero) { List <Disco> discos = new ApiSpotfy().GetDiscos(genero).ToList(); List <Disco> discosDB = Db.Set <Disco>().Where(g => g.Genero == genero).ToList(); List <Disco> discosNOVOS = new List <Disco>(); int cont = 0; foreach (Disco d in discos) { discos[cont].Preco = CashBack.Preco(genero); discos[cont].CashBack = CashBack.Calcular(genero); if (!discosDB.Exists(x => x.Id == d.Id)) { discosNOVOS.Add(d); } cont++; } if (discosNOVOS.Count() > 0) { Db.Set <Disco>().AddRange(discosNOVOS); Db.SaveChanges(); } return(discos.Count() > 0 ? discos : null); }
public GeneroMusical createGenero(generos pGenero) { int id = pGenero.PK_generos; string nombre = _manejadorDB.obtenerGenero(id).genero; GeneroMusical gene = new GeneroMusical(id, nombre); return(gene); }
public void Alterar(GeneroMusical generoMusical) { GeneroMusical generoMusicalSalvar = context.GeneroMusicais.First(x => x.generomusical_id == generoMusical.generomusical_id); generoMusicalSalvar.descricao = generoMusical.descricao; context.SaveChanges(); }
public bool crearGeneroMusical(GeneroMusical genero) { try { return(GeneroMusicalDAO.getInstance().crearGeneroMusical(genero)); } catch (Exception ex) { throw ex; } }
public GeneroMusical[] createListaGenero(List <generos> gens) { GeneroMusical[] arreglo = new GeneroMusical[gens.Count]; int contador = 0; foreach (generos i in gens) { arreglo[contador] = createGenero(i); contador++; } return(arreglo); }
private async Task <List <Disco> > ObterListaDiscosPorGenero(string token, GeneroMusical genero, List <Disco> listaDiscos) { int offset = 1; var albunsFinal = new List <Album>(); bool continuar = true; while (albunsFinal.Count < SpotifyConstants.MaxAlbuns && continuar) { var query = string.Format("q=genre%3A{0}&type=track&limit={1}&offset={2}", genero.ArgSpotify.ToLower(), SpotifyConstants.MaxAlbuns, offset); var url = _spotifySettings.SearchUrl + query; var consultaTrack = await GetSpotifyType <ConsultaTrack>(token, url); var albuns = consultaTrack?.tracks?.items?.Select(e => e.album).ToList(); albuns = albuns.GroupBy(e => e.id).Select(e => e.FirstOrDefault()).ToList(); var idAlbuns = albuns.Select(e => e.id).Distinct().ToList(); if (idAlbuns.Count <= 0) { continuar = false; } var idDiscos = listaDiscos.Select(e => e.CodSpotify).Distinct().ToList(); var idAlbunsFinais = albunsFinal.Select(e => e.id).Distinct().ToList(); idAlbunsFinais.AddRange(idDiscos); idAlbunsFinais = idAlbunsFinais.Distinct().ToList(); var idsExcept = idAlbuns.Except(idAlbunsFinais).ToList(); var lista = albuns.Where(e => idsExcept.Contains(e.id)).ToList(); albunsFinal.AddRange(lista); offset += SpotifyConstants.MaxAlbuns; } var ids = albunsFinal.Select(e => e.id).Distinct().ToList(); albunsFinal = albunsFinal.Skip(0).Take(SpotifyConstants.MaxAlbuns).ToList(); var discos = albunsFinal.Select(e => new Disco() { IdGeneroMusical = genero.IdGeneroMusical, Nome = e.name, CodSpotify = e.id, Preco = GerarPrecoRandom(), Artistas = string.Join(",", e.artists.Select(f => f.name).ToList()) }).ToList(); return(discos); }
public void agruparGenerosTest() { /* Arrange */ GeneroMusical g1 = new GeneroMusical(1, "Progressive Rock"); GeneroMusical g2 = new GeneroMusical(2, "Reggae Roots"); GeneroMusical[] _gens = { g1, g2 }; /* Act */ JObject[] _objs = _help.agruparGeneros(_gens); int id1 = (int)_objs[0]["Id"]; int id2 = (int)_objs[1]["Id"]; /* Assert */ Assert.AreEqual(id1, g1.Id); Assert.AreEqual(id2, g2.Id); }
public static double Preco(GeneroMusical generoMusical) { switch (generoMusical) { case GeneroMusical.POP: return(26.99); case GeneroMusical.MPB: return(29.99); case GeneroMusical.CLASSIC: return(40.89); case GeneroMusical.ROCK: return(25.00); default: return(1); } }
private DiscoSpotfy GetDiscosSpotify(GeneroMusical genero) { Token _token = GetToken(); string limit = "50"; if (_token == null || string.IsNullOrEmpty(genero.ToString())) { return(null); } //_token.access_token = "BQDxT-BwWogYb8i9EJdZf-zM_UFJKWCl6ulDN6n37iGyU3dJUSCDOBI4KfWwXuQO3Qrj6_u9IlGc6Yc_k2A"; //_token.expires_in = 3600; //_token.token_type = "Bearer"; var requisicaoWeb = WebRequest.CreateHttp($"https://api.spotify.com/v1/search?q={genero.ToString().ToLower()}&type=album&limit={limit}&offset=1"); requisicaoWeb.Method = "GET"; requisicaoWeb.ContentType = "application/x-www-form-urlencoded"; requisicaoWeb.Headers.Add("Authorization", string.Format("{0} {1}", _token.token_type, _token.access_token)); try { using (var resposta = requisicaoWeb.GetResponse()) { if (resposta.ContentLength > 0) { var streamDados = resposta.GetResponseStream(); StreamReader reader = new StreamReader(streamDados); object objResponse = reader.ReadToEnd(); DiscoSpotfy post = JsonConvert.DeserializeObject <DiscoSpotfy>(objResponse.ToString()); return(post); } } } catch (Exception ex) { } return(null); }
public IEnumerable <Disco> GetDiscos(GeneroMusical genero) { DiscoSpotfy discoSpotfy = GetDiscosSpotify(genero); if (discoSpotfy != null) { List <Disco> lstDisco = new List <Disco>(); foreach (Item iten in discoSpotfy.albums.items.OrderBy(d => d.name)) { Disco disco = new Disco { Id = iten.id, Nome = iten.name, Ano = iten.release_date.Substring(0, 4), href = iten.href, Imagem = iten.images.Select(s => s.url).Last(), //Preco = CashBack.Preco(genero), //CashBack = CashBack.ValorDia(genero), Genero = genero }; lstDisco.Add(disco); } return(lstDisco); } else { Disco disco = new Disco { Id = "NãoDefinido" }; List <Disco> ret = new List <Disco>(); ret.Add(disco); return(ret); } }
public IEnumerable <Disco> GetAll(GeneroMusical genero) { return(_repository.GetAll(genero)); }
public void Salvar(GeneroMusical generoMusical) { context.GeneroMusicais.Add(generoMusical); context.SaveChanges(); }
public IEnumerable <Disco> GetAll(GeneroMusical genero) { return(_service.GetAll(genero)); }
public static double Calcular(GeneroMusical generoMusical) { return((Preco(generoMusical) / 100) * ValorDia(generoMusical)); }