本文整理汇总了C#中RepositoryFactory.Save方法的典型用法代码示例。如果您正苦于以下问题:C# RepositoryFactory.Save方法的具体用法?C# RepositoryFactory.Save怎么用?C# RepositoryFactory.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RepositoryFactory
的用法示例。
在下文中一共展示了RepositoryFactory.Save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddChosenTeam
public void AddChosenTeam(string gameId, Team chosenTeam)
{
var game = GetGame(gameId);
if (game == null)
{
throw new NotFoundException($"Game with ID '{gameId}' not found");
}
game.CurrentTeam = chosenTeam;
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
repository.RegisterUpdate(game);
repository.Save();
}
}
示例2: Can_Save_New_Customer_With_Orders_And_Details
public void Can_Save_New_Customer_With_Orders_And_Details()
{
var customer = GetCustomer();
using (var repo = new RepositoryFactory().Create())
{
repo.Add(customer);
repo.Save();
}
using (var repo = new RepositoryFactory().Create())
{
var cust = repo.All<Customer>().SingleOrDefault(c => c.Email == "[email protected]");
Assert.IsNotNull(cust);
CollectionAssert.IsNotEmpty(cust.Orders);
Assert.IsNotNull(cust.Orders.First(o => o.OrderDetail != null).OrderDetail);
}
}
示例3: Can_Save_New_Customer
public void Can_Save_New_Customer()
{
var customer = new Customer
{
ContactName = "johnny",
Email = "[email protected]"
};
using (var repo = new RepositoryFactory().Create())
{
repo.Add(customer);
repo.Save();
}
using (var repo = new RepositoryFactory().Create())
{
var cust = repo.All<Customer>().SingleOrDefault(c => c.Email == "[email protected]");
Assert.IsNotNull(cust);
}
}
示例4: PlayMatchDay
public void PlayMatchDay(string seasonId, DateTime matchDay)
{
// First check if the given matchDay is the "next" match day
DateTime nextMatchDay = GetNextMatchDay(seasonId);
if (!nextMatchDay.Equals(matchDay))
{
throw new ConflictException("These matches can't be played now");
}
var matchesToPlay = GetBySeasonAndDate(seasonId, matchDay).ToList();
if (!matchesToPlay.Any())
{
throw new NotFoundException("There are no matches on this day");
}
foreach (var match in matchesToPlay)
{
Play(match);
}
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
var seasonManager = new SeasonManager(Game);
var postMatchManager = new PostMatchManager(repository, seasonManager);
postMatchManager.DoSomething(matchesToPlay);
// Save the result.
repository.RegisterUpdate(matchesToPlay);
repository.Save();
}
}
示例5: UpdateRating
//public void Delete(Team team)
//{
// using (var teamRepository = new RepositoryFactory().GetTeamRepository())
// {
// teamRepository.Delete(team);
// }
//}
public void UpdateRating(Team team, IEnumerable<Player> squad)
{
decimal teamRating = TeamRater.GetRating(squad);
team.Rating = teamRating;
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
repository.RegisterUpdate(team);
repository.Save();
}
}
示例6: CreateGame
public Game CreateGame()
{
using (var log = Logger.GetLogger(this))
{
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
// Insert the game into the database.
string gameName = DateTime.Now.ToString("yyyyMMddHHmmss");
var game = new Game { Name = gameName };
// Create teams and players.
var teamsAndPlayers = CreateTeamsAndPlayers(game);
// Insert teams.
repository.RegisterInsert(teamsAndPlayers.Teams);
// Insert players and skill scores.
repository.RegisterInsert(teamsAndPlayers.Players);
foreach (var player in teamsAndPlayers.Players)
{
repository.RegisterInsert(player.SkillScores);
}
var seasonManager = new SeasonManager(game);
// Create a season with match schedules.
var season = seasonManager.CreateFirstSeason(game, teamsAndPlayers.Teams, repository);
// Insert the season statistics and season/team statistics.
var seasonStatistics = new SeasonStatistics(season);
repository.RegisterInsert(seasonStatistics);
foreach (var team in teamsAndPlayers.Teams)
{
var seasonTeamStatistics = new SeasonTeamStatistics(season, team);
repository.RegisterInsert(seasonTeamStatistics);
}
// Assign the user a random team.
//TODO let the user choose a team via the GUI...
//var teamToManage = _listRandomizer.GetItem(teamsAndPlayers.Teams);
//game.CurrentTeam = teamToManage;
repository.RegisterInsert(game);
repository.Save();
return game;
}
}
}
示例7: DeleteGame
public void DeleteGame(Game game)
{
using (Logger.GetLogger(this, game))
{
var playerService = ServiceFactory.CreatePlayerService(game);
var teamService = ServiceFactory.CreateTeamService(game);
var seasonManager = new SeasonManager(game);
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
// Delete all players.
var players = playerService.GetAll(game);
repository.RegisterDelete(players);
// Delete all teams.
var teams = teamService.GetAll(game);
repository.RegisterDelete(teams);
// Delete the seasons, matches etc.
seasonManager.DeleteSeasons(repository);
// Delete the game itself.
repository.RegisterDelete(game);
repository.Save();
}
}
}
示例8: CreateGameForUser
public Game CreateGameForUser(string userId)
{
Game game;
using (var gameRepository = new RepositoryFactory().CreateGameRepository())
{
game = gameRepository.Find(x => x.UserId == null).FirstOrDefault();
}
if (game != null)
{
game.UserId = userId;
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
repository.RegisterUpdate(game);
repository.Save();
}
}
return game;
}
示例9: SubstitutePlayers
public void SubstitutePlayers(Player player1, Player player2)
{
// Update the team order of both players.
int oldPlayer1TeamOrder = player1.TeamOrder;
int oldPlayer2TeamOrder = player2.TeamOrder;
player1.TeamOrder = oldPlayer2TeamOrder;
player2.TeamOrder = oldPlayer1TeamOrder;
using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository())
{
repository.RegisterUpdate(player1);
repository.RegisterUpdate(player2);
repository.Save();
}
var team = player1.Team;
new TeamService(Game).UpdateRating(team);
}