Exemple #1
0
        public IHttpActionResult PutArtistInstrument(long id, ArtistInstrument artistInstrument)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != artistInstrument.artist_instrument_id)
            {
                return(BadRequest());
            }

            db.InsertOrUpdate(artistInstrument);

            try
            {
                db.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistInstrumentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public IHttpActionResult GetArtistInstrument(long id)
        {
            ArtistInstrument artistInstrument = db.Find(id);

            if (artistInstrument == null)
            {
                return(NotFound());
            }

            return(Ok(artistInstrument));
        }
Exemple #3
0
        public IHttpActionResult PostArtistInstrument(ArtistInstrument artistInstrument)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.InsertOrUpdate(artistInstrument);
            db.Save();

            return(CreatedAtRoute("DefaultApi", new { id = artistInstrument.artist_instrument_id }, artistInstrument));
        }
Exemple #4
0
 public void InsertOrUpdate(ArtistInstrument artistinstrument)
 {
     if (artistinstrument.artist_instrument_id == default(long))
     {
         // New entity
         context.ArtistInstruments.Add(artistinstrument);
     }
     else
     {
         // Existing entity
         context.Entry(artistinstrument).State = System.Data.Entity.EntityState.Modified;
     }
 }
Exemple #5
0
        public IHttpActionResult DeleteArtistInstrument(long id)
        {
            ArtistInstrument artistInstrument = db.Find(id);

            if (artistInstrument == null)
            {
                return(NotFound());
            }

            db.Delete(id);
            db.Save();

            return(Ok(artistInstrument));
        }
Exemple #6
0
        private void CalculateProbability(ArtistWithProbability artist, CharacteristicsQuery query)
        {
            if (query.Genres != null)
            {
                foreach (GenreModel genre in query.Genres)
                {
                    ArtistGenre artistGenre = artist.ArtistGenres.FirstOrDefault(ag => ag.GenreId == genre.Id);

                    if (artistGenre == null)
                    {
                        artist.CalculateProbability(0);
                        return;
                    }

                    artist.CalculateProbability(artistGenre.Probability);
                }
            }
            if (query.Instruments != null)
            {
                foreach (InstrumentModel instrument in query.Instruments)
                {
                    ArtistInstrument artistInstrument = artist.ArtistInstruments.FirstOrDefault(ai => ai.InstrumentId == instrument.Id);

                    if (artistInstrument == null)
                    {
                        artist.CalculateProbability(0);
                        return;
                    }

                    artist.CalculateProbability(artistInstrument.Probability);
                }
            }

            if (query.Tempos != null)
            {
                foreach (TempoModel tempo in query.Tempos)
                {
                    ArtistTempo artistTempo = artist.ArtistTempos.FirstOrDefault(at => at.TempoId == tempo.Id);

                    if (artistTempo == null)
                    {
                        artist.CalculateProbability(0);
                        return;
                    }

                    artist.CalculateProbability(artistTempo.Probability);
                }
            }

            if (query.Novelties != null)
            {
                foreach (NoveltyModel novelty in query.Novelties)
                {
                    ArtistNovelty artistNovelty = artist.ArtistNovelties.FirstOrDefault(an => an.NoveltyId == novelty.Id);

                    if (artistNovelty == null)
                    {
                        artist.CalculateProbability(0);
                        return;
                    }

                    artist.CalculateProbability(artistNovelty.Probability);
                }
            }
        }