Esempio n. 1
0
        public async Task <IActionResult> PutAlbumRating([FromRoute] int id, [FromBody] AlbumRating albumRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != albumRating.AlbumRatingId)
            {
                return(BadRequest());
            }

            _context.Entry(albumRating).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlbumRatingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = TrackId;
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Artist != null ? Artist.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AlbumArtist != null ? AlbumArtist.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Composer != null ? Composer.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Album != null ? Album.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Genre != null ? Genre.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Kind != null ? Kind.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Size.GetHashCode();
         hashCode = (hashCode * 397) ^ (PlayingTime != null ? PlayingTime.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ TrackNumber.GetHashCode();
         hashCode = (hashCode * 397) ^ Year.GetHashCode();
         hashCode = (hashCode * 397) ^ DateModified.GetHashCode();
         hashCode = (hashCode * 397) ^ DateAdded.GetHashCode();
         hashCode = (hashCode * 397) ^ BitRate.GetHashCode();
         hashCode = (hashCode * 397) ^ SampleRate.GetHashCode();
         hashCode = (hashCode * 397) ^ PlayCount.GetHashCode();
         hashCode = (hashCode * 397) ^ PlayDate.GetHashCode();
         hashCode = (hashCode * 397) ^ PartOfCompilation.GetHashCode();
         hashCode = (hashCode * 397) ^ (Location != null ? Location.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Rating.GetHashCode();
         hashCode = (hashCode * 397) ^ AlbumRating.GetHashCode();
         hashCode = (hashCode * 397) ^ AlbumRatingComputed.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 3
0
        public async Task <IActionResult> PostAlbumRating([FromBody] AlbumRating albumRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.AlbumRating.Add(albumRating);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAlbumRating", new { id = albumRating.AlbumRatingId }, albumRating));
        }
        public async Task <AlbumRating> CreateAlbumRatingAsync(AlbumRating albumRating)
        {
            if (db != null)
            {
                albumRating.UniqueId = Guid.NewGuid();
                await db.AlbumRating.AddAsync(albumRating);

                await db.SaveChangesAsync();

                return(await GetAlbumRatingByIdAsync(albumRating.UniqueId));
            }

            return(null);
        }
Esempio n. 5
0
        public void Task_Get_With_Relation_Return_Equal()
        {
            var factory = new ConnectionFactory();
            var context = factory.CreateContextForSQLite();

            for (int i = 1; i < 4; i++)
            {
                var album = new Albums()
                {
                    AlbumId          = i,
                    AlbumName        = "Category " + i,
                    AlbumImagPath    = "../Test/Image.png",
                    AlbumPrice       = 1,
                    AlbumReleaseDate = DateTime.Now,
                    IsActive         = true,
                    CreatedDate      = DateTime.Now,
                    ModifiedDate     = DateTime.Now,
                    CreatedBy        = 1,
                    ModifiedBy       = 1
                };
                context.Albums.Add(album);
            }

            for (int i = 1; i < 4; i++)
            {
                var albumRating = new AlbumRating()
                {
                    AlbumRatingId = i,
                    AlbumId       = 2,
                    AlbumRatingBy = i,
                    AlbumRatings  = i,
                    IsActive      = true,
                    CreatedDate   = DateTime.Now,
                    ModifiedDate  = DateTime.Now,
                    CreatedBy     = 1,
                    ModifiedBy    = 1
                };
                context.AlbumRating.Add(albumRating);
            }
            context.SaveChanges();

            var albumsRepo    = new AlbumsRepository(context);
            var albumsService = new AlbumService(albumsRepo);

            var result = albumsService.GetAlbumDetailsByAlbumId(2);

            Assert.Equal(2, result.AlbumId);
        }
        public bool CreateAlbumRating(AlbumRatingCreate model)
        {
            // format the new AlbumRating record
            var entity =
                new AlbumRating()
            {
                OwnerId = _userId,
                AlbumId = model.AlbumId,
                AlbumIndividualRating = model.AlbumIndividualRating,
                Album = model.Album
            };

            // Add the new AlbumRating to the table
            using (var ctx = new ApplicationDbContext())
            {
                ctx.AlbumRatings.Add(entity);
                bool addedAlbumRating = ctx.SaveChanges() == 1;
                if (!addedAlbumRating)
                {
                    return(false);
                }
            }

            // Update the Album record
            using (var ctx = new ApplicationDbContext())
            {
                // retrieve the AlbumRating record we just posted so we can follow the foreign key to the Album record
                var newAlbumRating =
                    ctx
                    .AlbumRatings
                    .Single(e => e.AlbumRatingId == entity.AlbumRatingId && e.OwnerId == _userId);

                // Update the fields in the Album record at the other end of the foreign key
                newAlbumRating.Album.CulumativeRating += model.AlbumIndividualRating;
                newAlbumRating.Album.NumberOfRatings  += 1;

                newAlbumRating.Album.Rating = newAlbumRating.Album.CulumativeRating / newAlbumRating.Album.NumberOfRatings;

                return(ctx.SaveChanges() == 1);
            }
        } // CreateAlbumRating
Esempio n. 7
0
        public IActionResult Rate(int id, int rating)
        {
            var userID = _userManager.GetUserId(User);

            if (_context.AlbumRatings.SingleOrDefault(m => (m.UserID == userID) && (m.AlbumID == id)) == null)
            {
                var Rating = new AlbumRating {
                    UserID = userID, AlbumID = id, Rating = rating
                };
                _context.Add(Rating);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var album = _context.Albums.SingleOrDefault(m => m.AlbumID == id);

            if (album == null)
            {
                return(NotFound());
            }
            ViewData["Title"] = album.Title;
            return(View(rating));
        }