/// <summary> /// The <c>UnitOfWork</c> constructor. /// </summary> /// <param name="context">the context on which the <c>UnitOfWork</c> will operate.</param> public UnitOfWork(MemoryGameContext context) { _context = context; Players = new PlayerRepository(_context); CardDecks = new CardDeckRepository(_context); Matches = new Repository <Match>(_context); Accounts = new AccountRepository(_context); }
/// <inheritdoc/> public bool RegisterNewPlayer(PlayerDto playerDTO, string salt) { Account newAccount = new Account() { EmailAddress = playerDTO.EmailAddress, Username = playerDTO.Username, Password = playerDTO.Password, Salt = salt, EmailWasVerified = false, ActivationToken = playerDTO.VerificationToken }; Player newPlayer = new Player() { EmailAddress = newAccount.EmailAddress, Score = 0 }; MemoryGameContext memoryGameContext = new MemoryGameContext(); UnitOfWork unitOfWork = new UnitOfWork(memoryGameContext); try { unitOfWork.Accounts.Add(newAccount); unitOfWork.Players.Add(newPlayer); int rowsAffected = unitOfWork.Complete(); return(rowsAffected > 0); } catch (SqlException sqlException) { _logger.Fatal("PlayerRegistryService.cs: An exception was thrown while trying to register both " + "Account and Player entities. " + "Method RegisterNewPlayer, line 67", sqlException); throw; } catch (EntityException entityException) { _logger.Fatal("PlayerRegistryService.cs: An exception was thrown while trying to access the database. " + "It is possible that the database is corrupted or that it does not exist. " + "Method RegisterNewPlayer, line 67", entityException); throw; } finally { unitOfWork.Dispose(); } }
public void TestInitialize() { _data = new List <Account>() { new Account { EmailAddress = "*****@*****.**", Username = "******", Password = "******", Salt = "123456", EmailWasVerified = true, ActivationToken = null, RecoveryToken = null, Player = null }, new Account { EmailAddress = "*****@*****.**", Username = "******", Password = "******", Salt = "123456", EmailWasVerified = true, ActivationToken = null, RecoveryToken = null, Player = null }, new Account { EmailAddress = "*****@*****.**", Username = "******", Password = "******", Salt = "123456", EmailWasVerified = false, ActivationToken = null, RecoveryToken = null, Player = null }, }; _mockSet = DbContextMock.GetQueryableMockDbSet(_data); _mockContext = DbContextMock.GetContext(_mockSet); _repository = new AccountRepository(_mockContext); _unitOfWork = new UnitOfWork(_mockContext); }
public IndexModel(MemoryGameContext context, UserManager <User> userManager) : base(context) { Header = "All Lists"; _userManager = userManager; }
public async static void Initialize(IServiceProvider serviceProvider) { using (var context = new MemoryGameContext( serviceProvider.GetRequiredService <DbContextOptions <MemoryGameContext> >())) { // Look for any Records. if (context.Record.Any()) { return; // DB has been seeded } var list = await context.List.FirstOrDefaultAsync(); context.Record.AddRange( new Record { List = list, ListId = list.ID, Word = "Table", Translation = "Стол" }, new Record { List = list, ListId = list.ID, Word = "Bird", Translation = "Птица" }, new Record { List = list, ListId = list.ID, Word = "Animal", Translation = "Животное" }, new Record { List = list, ListId = list.ID, Word = "Wind", Translation = "Ветер" }, new Record { List = list, ListId = list.ID, Word = "Water", Translation = "Вода" }, new Record { List = list, ListId = list.ID, Word = "Food", Translation = "Еда" }, new Record { List = list, ListId = list.ID, Word = "Earth", Translation = "Земля(планета)" }, new Record { List = list, ListId = list.ID, Word = "Mist", Translation = "Туман" }, new Record { List = list, ListId = list.ID, Word = "Rain", Translation = "Дождь" }, new Record { List = list, ListId = list.ID, Word = "Sweet", Translation = "Сладкий" }, new Record { List = list, ListId = list.ID, Word = "Weather", Translation = "Погода" }, new Record { List = list, ListId = list.ID, Word = "Ocean", Translation = "Океан" } ); context.SaveChanges(); } }
/// <inheritdoc/> public PlayerRepository(MemoryGameContext context) : base(context) { }
public static UnitOfWork GetUnitOfWork(MemoryGameContext context) { var mockUnitOfWork = new Mock <UnitOfWork>(context); return(mockUnitOfWork.Object); }
public DalUser(MemoryGameContext context, IMapper mapper) : base(context) { _mapper = mapper; _context = context; _userEntity = _context.Set <User>(); }
public DalBase(MemoryGameContext Context) { _context = Context; entities = _context.Set <TEntity>(); }