public ActionResult <Song> Post([FromBody] Song bodySong) { var serviceResult = _songService.AddSong_and_Update_Popularity_Price_FromAlbum(bodySong); if (serviceResult.ResponseCode != ResponseCode.Success) { return(BadRequest(serviceResult.Error)); } var result = new Song { songName = serviceResult.Result.songName, artistName = serviceResult.Result.artistName, bought = serviceResult.Result.bought, popularity = serviceResult.Result.popularity, id = serviceResult.Result.id, price = serviceResult.Result.price, albumId = serviceResult.Result.albumId, duration = serviceResult.Result.duration }; return(Ok(result)); //Song nSong = new Song //{ // albumId = bodySong.albumId, // artistName = bodySong.artistName, // bought = bodySong.bought, // duration = bodySong.duration, // popularity=bodySong.popularity, // price=bodySong.price, // id=bodySong.id, // songName=bodySong.songName, //}; //var songsinAlbum = dbContext.Songs.Where(x => x.albumId == bodySong.albumId); //var score = songsinAlbum.Sum(x => x.popularity)/songsinAlbum.Count(); //dbContext.Songs.Add(nSong); //dbContext.SaveChanges(); //var modifiedAlbum = dbContext.Albums.FirstOrDefault(x => x.id == nSong.albumId); //modifiedAlbum.score = score; //var fullAlbumprice = songsinAlbum.Sum(x => x.price) + nSong.price; //modifiedAlbum.price = fullAlbumprice - (fullAlbumprice * 0.1); //dbContext.Albums.Update(modifiedAlbum); //dbContext.SaveChanges(); }