public async Task Handle(BookSubmissionCommand command)
        {
            var bookExists = await _context
                             .Books
                             .Where(b => b.Author.ToUpper() == command.Author.ToUpper())
                             .Where(b => b.Type == command.Type)
                             .Where(b => b.Title.ToUpper() == command.Title.ToUpper())
                             .Where(b => b.UserId == command.User.Id)
                             .AnyAsync();

            if (bookExists)
            {
                return;
            }

            var newRecord = _mapper.Map <BookRecord>(command);

            if (newRecord.TimesCompleted > 0)
            {
                newRecord.CompletionStatus = CompletionStatusReference.Completed;
            }

            var dateAdded = DateTimeOffset.UtcNow;

            newRecord.AddedOn         = dateAdded;
            newRecord.CreatedByUserId = command.User.Id;
            newRecord.UpdatedOn       = dateAdded;
            newRecord.UpdatedByUserId = command.User.Id;

            var newCheckoutRecord = _mapper.Map <CheckoutRecord>(command.Checkout);

            newCheckoutRecord.CreatedByUserId    = command.User.Id;
            newCheckoutRecord.CreatedOn          = dateAdded;
            newCheckoutRecord.CheckedOutByUserId = command.User.Id;
            newCheckoutRecord.CreatedOn          = dateAdded;
            newCheckoutRecord.EntityType         = "BOOK";
            newCheckoutRecord.ModifiedByUserId   = command.User.Id;
            newCheckoutRecord.ModifiedOn         = dateAdded;

            await _context.Checkouts.AddAsync(newCheckoutRecord);

            newRecord.CheckoutId = newCheckoutRecord.Id;

            var newStorageRecord = _mapper.Map <ItemStorageRecord>(command.ItemStorage);

            newStorageRecord.CreatedByUserId  = command.User.Id;
            newStorageRecord.CreatedOn        = dateAdded;
            newStorageRecord.EntityType       = "BOOK";
            newStorageRecord.ModifiedByUserId = command.User.Id;
            newStorageRecord.ModifiedOn       = dateAdded;

            await _context.ItemStorages.AddAsync(newStorageRecord);

            newRecord.ItemStorageId = newStorageRecord.Id;

            await _context.Books.AddAsync(newRecord);

            await _context.SaveChangesAsync();
        }
示例#2
0
        public async Task Handle(AlbumSubmissionCommand command)
        {
            var albumExists = await _context
                              .Albums
                              .Where(a => a.Artist.ToUpper() == command.Artist.ToUpper())
                              .Where(a => a.MediaType == command.MediaType)
                              .Where(a => a.Title.ToUpper() == command.Title.ToUpper())
                              .Where(a => a.UserId == command.User.Id)
                              .AnyAsync();

            if (albumExists)
            {
                return;
            }

            var newRecord = _mapper.Map <AlbumRecord>(command);

            if (newRecord.TimesCompleted > 0)
            {
                newRecord.CompletionStatus = CompletionStatusReference.Completed;
            }

            var dateAdded = DateTimeOffset.UtcNow;

            newRecord.AddedOn         = dateAdded;
            newRecord.UpdatedOn       = dateAdded;
            newRecord.CreatedByUserId = command.User.Id;
            newRecord.UpdatedByUserId = command.User.Id;

            var newCheckoutRecord = _mapper.Map <CheckoutRecord>(command.Checkout);

            newCheckoutRecord.CreatedByUserId    = command.User.Id;
            newCheckoutRecord.CreatedOn          = dateAdded;
            newCheckoutRecord.CheckedOutByUserId = command.User.Id;
            newCheckoutRecord.CreatedOn          = dateAdded;
            newCheckoutRecord.EntityType         = "ALBUM";
            newCheckoutRecord.ModifiedByUserId   = command.User.Id;
            newCheckoutRecord.ModifiedOn         = dateAdded;

            await _context.Checkouts.AddAsync(newCheckoutRecord);

            newRecord.CheckoutId = newCheckoutRecord.Id;

            var newStorageRecord = _mapper.Map <ItemStorageRecord>(command.ItemStorage);

            newStorageRecord.CreatedByUserId  = command.User.Id;
            newStorageRecord.CreatedOn        = dateAdded;
            newStorageRecord.EntityType       = "ALBUM";
            newStorageRecord.ModifiedByUserId = command.User.Id;
            newStorageRecord.ModifiedOn       = dateAdded;

            await _context.ItemStorages.AddAsync(newStorageRecord);

            newRecord.ItemStorageId = newStorageRecord.Id;

            await _context.Albums.AddAsync(newRecord);

            await _context.SaveChangesAsync();
        }
示例#3
0
        private async Task InitializeRecords()
        {
            var expiredToken = new RefreshTokenRecord
            {
                ExpiresOn = DateTimeOffset.UtcNow.AddDays(-1),
                UserId    = _testCommand.UserId
            };

            await _context.RefreshTokens.AddAsync(expiredToken);

            await _context.SaveChangesAsync();
        }
示例#4
0
        public async Task Handler_Does_Not_Add_Game_With_Same_Title_And_Media_Type_For_User()
        {
            var existingGame = new GameRecord {
                Title = _testCommand.Title, Type = _testCommand.Type, UserId = _testCommand.User.Id
            };

            await _context.Games.AddAsync(existingGame);

            await _context.SaveChangesAsync();

            await _handler.Handle(_testCommand);

            var game = await _context
                       .Games
                       .Where(g => g.Title == _testCommand.Title)
                       .Where(g => g.Type == _testCommand.Type)
                       .Where(g => g.UserId == _testCommand.User.Id)
                       .CountAsync();

            game.Should().Be(1);
        }
        public async Task Handler_Does_Not_Add_Record_With_Same_Artist_Media_Type_And_Title_For_User()
        {
            var existingAlbum = new AlbumRecord
            {
                Artist    = _testCommand.Artist,
                MediaType = _testCommand.MediaType,
                Title     = _testCommand.Title,
                UserId    = _testCommand.User.Id
            };

            await _context.Albums.AddAsync(existingAlbum);

            await _context.SaveChangesAsync();

            await _handler.Handle(_testCommand);

            var album = await _context.Albums.CountAsync(a
                                                         => a.Artist == _testCommand.Artist &&
                                                         a.MediaType == _testCommand.MediaType &&
                                                         a.Title == _testCommand.Title &&
                                                         a.UserId == _testCommand.User.Id);

            album.Should().Be(1);
        }
        public async Task Handler_Does_Not_Add_Record_With_Same_Artist_Media_Type_And_Title_For_User()
        {
            var existingBook = new BookRecord
            {
                Author = _testCommand.Author,
                Type   = _testCommand.Type,
                Title  = _testCommand.Title,
                UserId = _testCommand.User.Id
            };

            await _context.Books.AddAsync(existingBook);

            await _context.SaveChangesAsync();

            await _handler.Handle(_testCommand);

            var book = await _context.Books.CountAsync(a
                                                       => a.Author == _testCommand.Author &&
                                                       a.Type == _testCommand.Type &&
                                                       a.Title == _testCommand.Title &&
                                                       a.UserId == _testCommand.User.Id);

            book.Should().Be(1);
        }
        private async Task InitializeRecords()
        {
            await _writeContext.Wishes.AddAsync(_testRecord);

            await _writeContext.SaveChangesAsync();
        }
        private async Task InitializeRecords()
        {
            await _context.Books.AddAsync(_testBook);

            await _context.SaveChangesAsync();
        }