本文整理汇总了C#中DAL.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DAL.SaveChanges方法的具体用法?C# DAL.SaveChanges怎么用?C# DAL.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DAL
的用法示例。
在下文中一共展示了DAL.SaveChanges方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SeedContext
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
/// <summary>
/// Seeds the default context.
/// </summary>
/// <param name="context">The context.</param>
public static void SeedContext(DAL.DefaultContext context)
{
DbSet<District> districtSet = context.Districts;
FixDistricts(ref districtSet);
DbSet<PhoneNumberPrefix> phoneNumberPrefixSet = context.PhoneNumberPrefixes;
FixPhoneNumberPrefixes(ref phoneNumberPrefixSet);
DbSet<Meeting> meetingSet = context.Meetings;
if (context.MeetingTitleTypes.All(mtt => mtt.MeetingType != MeetingType.SetkaniTymu))
{
DbSet<MeetingTitleType> meetingTitleTypeSet = context.MeetingTitleTypes;
DbContext dbContext = context;
FixMeetingTitleTypesAndMeetings(ref dbContext, ref meetingTitleTypeSet, ref meetingSet);
}
if (context.BankAccounts.Any(ba => ba.Token == "V2-1-0-21"))
{
DbSet<BankAccount> bankAccountSet = context.BankAccounts;
FixBankAccountsAndMeetings(ref bankAccountSet, ref meetingSet);
}
context.SaveChanges();
if (context.UserProfiles.Any())
return;
CreateAdminAccount("DefaultConnection");
}
示例2: CheckWinningBets
private static void CheckWinningBets(int gameId, DAL.BettingRoomEntities ctx, DAL.Game game)
{
var winningBets = ctx.BetOneGames.Where(b => b.GameId == gameId && b.C1X2 == game.Result1X2).ToList();
if (winningBets.Count > 0)
{
foreach (var bet in winningBets)
{
bet.WonOrLose = "WON";
var account = ctx.AccountBalances.Where(a => a.UserId == bet.UserId).FirstOrDefault();
account.AmountInEuro = account.AmountInEuro + (bet.BetAmount * bet.Odds);
var transaction = new DAL.Transaction
{
AccountId = account.Id,
TransactionType = "Winning",
TransactionTime = game.GameTime.AddHours(2),
Amount = bet.BetAmount * bet.Odds,
};
ctx.Transactions.Add(transaction);
ctx.SaveChanges();
}
}
}
示例3: CheckLosingBets
private static void CheckLosingBets(int gameId, DAL.BettingRoomEntities ctx, DAL.Game game)
{
var loosingBets = ctx.BetOneGames.Where(b => b.GameId == gameId && b.C1X2 != game.Result1X2).ToList();
if (loosingBets.Count > 0)
{
foreach (var bet in loosingBets)
{
bet.WonOrLose = "LOST";
ctx.SaveChanges();
}
}
}
示例4: LoadTeamsPerCategory
private void LoadTeamsPerCategory(List<DAL.Team> teams, DAL.AntwerpRCEntities context, string user)
{
foreach (var team in teams)
{
var doc = browserSession.GetDoc(team.CompetitionUrl);
var table = doc.DocumentNode.Descendants("table")
.FirstOrDefault(
t => t.Descendants("tr").Count() > 1 &&
t.Descendants("tr").Skip(1).FirstOrDefault() != null &&
t.Descendants("tr").Skip(1).First().Attributes.Contains("class") &&
t.Descendants("tr").Skip(1).First().Attributes["class"].Value.Contains("comp_title"));
if (table != null)
{
int skip = 2;
var rows = table.Descendants("tr").Skip(skip).ToList();
if (rows.Any())
{
foreach (var row in rows)
{
var clubElement = row.Descendants("td").Skip(1).Take(1).FirstOrDefault();
if (clubElement != null)
{
var clubName = clubElement.InnerText.CleanHtml();
Console.WriteLine("Club {0} found in table", clubName);
var existingClub =
context.Club.FirstOrDefault(
c =>
c.ClubName == clubName ||
c.ClubAlias.Any(a => a.Alias == clubName));
if (existingClub != null)
{
if (existingClub.TeamClub.All(tc => tc.TeamId != team.TeamId))
team.TeamClub.Add(new TeamClub() { Club = existingClub, AuditCreatedBy = user, AuditCreatedOn = DateTime.Now });
}
else
{
team.TeamClub.Add(new TeamClub() { Club = CreateClub(clubName, user), AuditCreatedBy = user, AuditCreatedOn = DateTime.Now });
}
}
}
context.SaveChanges();
}
}
}
}
示例5: LoadTableForTeams
private void LoadTableForTeams(IEnumerable<DAL.Team> teams, DAL.AntwerpRCEntities context, string user, DateTime calculationDate)
{
try
{
foreach (var team in teams)
{
var table = new DAL.ScoreTable()
{
AuditCreatedBy = user,
AuditCreatedOn = DateTime.Now,
TeamId = team.TeamId,
SelfCalculated = true,
CreatedOn = calculationDate
};
//team.ScoreTable.Add(table);
//context.SaveChanges();
var lines = LoadTableForTeam(team, table, context, user,calculationDate);
//Get the last table and compare
bool saveNewTable = true;
var oldTable =
context.ScoreTable.AsNoTracking().OrderByDescending(t => t.CreatedOn)
.FirstOrDefault(t => t.TeamId == team.TeamId);
if (oldTable != null)
{
if (table.Equals(oldTable))
{
saveNewTable = false;
}
}
if (saveNewTable)
{
table.ScoreTableLine.Clear();
context.ScoreTable.Add(table);
context.SaveChanges();
foreach (var scoreTableLine in lines)
{
scoreTableLine.ScoreTable = table;
context.ScoreTableLine.Add(scoreTableLine);
context.SaveChanges();
}
}
}
}
catch (Exception ex)
{
throw;
}
}
示例6: LoadGamesPerCategory
private void LoadGamesPerCategory(IEnumerable<DAL.Team> teams, DAL.AntwerpRCEntities context, string user)
{
foreach (var team in teams)
{
var doc = browserSession.GetDoc(team.CompetitionUrl);
var teamClubs = team.TeamClub.ToList();
int take = 1;
take = take + teamClubs.Count / 2;
if (teamClubs.Count % 2 > 0)
take++;
var table =
doc.DocumentNode.Descendants("table")
.FirstOrDefault(
t => t.Attributes.Contains("class") && t.Attributes["class"].Value.Contains("clubentrees"));
if (table != null)
{
int skip = 1;
var rows = table.Descendants("tr").Skip(skip).Take(take).ToList();
while (rows.Any())
{
var dateRow = rows[0];
DateTime? date = ProcessDateRow(dateRow);
if (date.HasValue)
{
foreach (var row in rows.Skip(1))
{
Game game = ProcessGameRow(row, date.Value, teamClubs, context, user);
if (game != null && game.GameId <= 0)
{
//Add game
context.Game.Add(game);
}
}
context.SaveChanges();
}
skip = skip + take + 1;
rows = table.Descendants("tr").Skip(skip).Take(take + 1).ToList();
}
}
}
}
示例7: AddExeption
public static void AddExeption(Exception ex, string methodName, DAL.WorkitContext context)
{
context.Loggers.Add(new Logger {Id = Guid.NewGuid(), MethodName = methodName, Message = ex.Message, ExeptionTime = DateTime.Now });
context.SaveChanges();
}
示例8: CreateTheTransaction
private static void CreateTheTransaction(Models.BetOneModel model, DAL.BettingRoomEntities ctx, DAL.AccountBalance account)
{
ctx.Transactions.Add(new DAL.Transaction
{
AccountId = account.Id,
Amount = model.BetAmount,
TransactionTime = DateTime.Now,
TransactionType = "Bet",
});
ctx.SaveChanges();
}
示例9: CreateTheBet
private static void CreateTheBet(Models.BetOneModel model, DAL.BettingRoomEntities ctx)
{
ctx.BetOneGames.Add(new DAL.BetOneGame
{
BetAmount = model.BetAmount,
C1X2 = model._1X2,
Odds = model.Odds,
GameId = model.GameId,
WonOrLose = "NOT FINISH",
BetTime = DateTime.Now,
UserId = model.UserId,
});
ctx.SaveChanges();
}