Exemplo n.º 1
0
        } // CreateSongRatingService

        /// <summary>
        /// Edits a Song Rating
        /// </summary>
        /// <param name="songRating"></param>
        /// <returns></returns>
        public IHttpActionResult Put(SongRatingEdit songRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateSongRatingService();

            if (!service.UpdateSongRating(songRating))
            {
                return(InternalServerError());
            }

            return(Ok());
        } // Put
Exemplo n.º 2
0
        } // GetsongRatingById

        public bool UpdateSongRating(SongRatingEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .SongRatings
                    .Single(e => e.SongRatingId == model.SongRatingId && e.OwnerId == _userId);


                entity.Song.CulumativeRating = entity.Song.CulumativeRating - entity.SongIndividualRating;
                entity.Song.CulumativeRating = model.SongIndividualRating + entity.Song.CulumativeRating;
                entity.Song.Rating           = entity.Song.CulumativeRating / entity.Song.NumberOfRatings;

                entity.SongId = model.SongId;
                entity.SongIndividualRating = model.SongIndividualRating;

                return(ctx.SaveChanges() == 1);
            }
        } // UpdateArtistRating