本文整理汇总了C#中ZkData.ZkDataContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# ZkDataContext.SaveChanges方法的具体用法?C# ZkDataContext.SaveChanges怎么用?C# ZkDataContext.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZkData.ZkDataContext
的用法示例。
在下文中一共展示了ZkDataContext.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddContribution
public ActionResult AddContribution(int accountID,int kudos, string item, string currency, double gross, double grossEur, double netEur, string email, string comment, bool isSpring, DateTime date) {
using (var db = new ZkDataContext()) {
var acc = db.Accounts.Find(accountID);
var contrib = new Contribution()
{
AccountID = accountID,
ManuallyAddedAccountID = Global.AccountID,
KudosValue = kudos,
ItemName = item,
IsSpringContribution = isSpring,
Comment = comment,
OriginalCurrency = currency,
OriginalAmount = gross,
Euros = grossEur,
EurosNet = netEur,
Time = date,
Name = acc.Name,
Email = email
};
db.Contributions.InsertOnSubmit(contrib);
db.SaveChanges();
acc.Kudos = acc.KudosGained - acc.KudosSpent;
db.SaveChanges();
}
return RedirectToAction("Index");
}
示例2: GenerateTechs
public static void GenerateTechs()
{
var db = new ZkDataContext();
db.StructureTypes.DeleteAllOnSubmit(db.StructureTypes.Where(x => x.Unlock != null));
db.SaveChanges();
foreach (var u in db.Unlocks.Where(x => x.UnlockType == UnlockTypes.Unit))
{
var s = new StructureType()
{
BattleDeletesThis = false,
Cost = u.XpCost / 2,
MapIcon = "techlab.png",
DisabledMapIcon = "techlab_dead.png",
Name = u.Name,
Description = string.Format("Access to {0} and increases influence gains", u.Name),
TurnsToActivate = u.XpCost / 100,
IsBuildable = true,
IsIngameDestructible = true,
IsBomberDestructible = true,
Unlock = u,
UpkeepEnergy = u.XpCost / 5,
IngameUnitName = "pw_" + u.Code,
};
db.StructureTypes.InsertOnSubmit(s);
}
db.SaveChanges();
}
示例3: Redeem
public ActionResult Redeem(string code) {
var db = new ZkDataContext();
if (string.IsNullOrEmpty(code)) return Content("Code is empty");
var contrib = db.Contributions.SingleOrDefault(x => x.RedeemCode == code);
if (contrib == null) return Content("No contribution with that code found");
if (contrib.AccountByAccountID != null) return Content(string.Format("This contribution has been assigned to {0}, thank you.", contrib.AccountByAccountID.Name));
var acc = db.Accounts.Find(Global.AccountID);
contrib.AccountByAccountID = acc;
db.SaveChanges();
acc.Kudos = acc.KudosGained - acc.KudosSpent;
db.SaveChanges();
return Content(string.Format("Thank you!! {0} Kudos have been added to your account {1}", contrib.KudosValue, contrib.AccountByAccountID.Name));
}
示例4: ChangeFeaturedOrder
public ActionResult ChangeFeaturedOrder(int id, float? featuredOrder, string script)
{
var db = new ZkDataContext();
var mis = db.Missions.SingleOrDefault(x => x.MissionID == id);
mis.FeaturedOrder = featuredOrder;
if (mis.IsScriptMission && !string.IsNullOrEmpty(script)) mis.Script = script;
db.SaveChanges();
var order = 1;
if (featuredOrder.HasValue) foreach (var m in db.Missions.Where(x => x.FeaturedOrder != null).OrderBy(x => x.FeaturedOrder)) m.FeaturedOrder = order++;
db.SaveChanges();
return RedirectToAction("Index");
}
示例5: Delete
public ActionResult Delete(int id)
{
var db = new ZkDataContext();
db.Missions.First(x => x.MissionID == id).IsDeleted = true;
db.SaveChanges();
return RedirectToAction("Index");
}
示例6: StoreChatHistoryAsync
public Task StoreChatHistoryAsync(Say say)
{
return Task.Run(async () =>
{
await storeHistorySemaphore.WaitAsync();
try
{
using (var db = new ZkDataContext())
{
var historyEntry = new LobbyChatHistory();
historyEntry.SetFromSay(say);
db.LobbyChatHistories.Add(historyEntry);
db.SaveChanges();
}
}
catch (Exception ex)
{
Trace.TraceError("Error saving chat history: {0}", ex);
}
finally
{
storeHistorySemaphore.Release();
}
});
}
示例7: ChangePermissions
public ActionResult ChangePermissions(int accountID, bool zkAdmin, bool vpnException)
{
var db = new ZkDataContext();
Account acc = db.Accounts.Single(x => x.AccountID == accountID);
Account adminAcc = Global.Account;
Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("Permissions changed for {0} {1} by {2}", acc.Name, Url.Action("Detail", "Users", new { id = acc.AccountID }, "http"), adminAcc.Name));
if (acc.IsZeroKAdmin != zkAdmin)
{
//reset chat priviledges to 2 if removing adminhood; remove NW subsciption to admin channel
// FIXME needs to also terminate forbidden clan/faction subscriptions
Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format(" - Admin status: {0} -> {1}", acc.IsZeroKAdmin, zkAdmin));
acc.IsZeroKAdmin = zkAdmin;
}
if (acc.HasVpnException != vpnException)
{
Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format(" - VPN exception: {0} -> {1}", acc.HasVpnException, vpnException));
acc.HasVpnException = vpnException;
}
db.SaveChanges();
Global.Server.PublishAccountUpdate(acc);
return RedirectToAction("Detail", "Users", new { id = acc.AccountID });
}
示例8: RemoveBlockedCompany
public ActionResult RemoveBlockedCompany(int companyID)
{
ZkDataContext db = new ZkDataContext();
BlockedCompany todel = db.BlockedCompanies.First(x => x.CompanyID == companyID);
string name = todel.CompanyName;
db.BlockedCompanies.DeleteOnSubmit(todel);
db.SaveChanges();
var str = string.Format("{0} removed blocked VPN company: {1}", Global.Account.Name, name);
Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, str);
return RedirectToAction("BlockedVPNs");
}
示例9: DeleteResource
public static ReturnValue DeleteResource(string internalName)
{
var db = new ZkDataContext();
var todel = db.Resources.SingleOrDefault(x => x.InternalName == internalName);
if (todel == null) return ReturnValue.ResourceNotFound;
RemoveResourceFiles(todel);
db.Resources.Remove(todel);
db.SaveChanges();
return ReturnValue.Ok;
}
示例10: NewPoll
public ActionResult NewPoll(string question, string answers, bool? isAnonymous)
{
var p = new Poll() { CreatedAccountID = Global.AccountID, IsHeadline = true, QuestionText = question, IsAnonymous = isAnonymous == true, };
var db = new ZkDataContext();
foreach (var a in answers.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) p.PollOptions.Add(new PollOption() { OptionText = a });
db.Polls.InsertOnSubmit(p);
db.SaveChanges();
return RedirectToAction("UserVotes", new { id = Global.AccountID });
}
示例11: ChangeHideCountry
public ActionResult ChangeHideCountry(int accountID, bool hideCountry)
{
var db = new ZkDataContext();
Account acc = db.Accounts.Single(x => x.AccountID == accountID);
if (hideCountry) acc.Country = "??";
// TODO reimplement ? Global.Nightwatch.Tas.SetHideCountry(acc.Name, hideCountry);
db.SaveChanges();
return RedirectToAction("Detail", "Users", new { id = acc.AccountID });
}
示例12: DeletePost
public ActionResult DeletePost(int? postID) {
var db = new ZkDataContext();
var post = db.ForumPosts.Single(x => x.ForumPostID == postID);
var thread = post.ForumThread;
var threadID = thread.ForumThreadID;
//int index = post.ForumThread.ForumPosts.IndexOf(post);
var page = GetPostPage(post);
db.ForumPosts.DeleteOnSubmit(post);
if (thread.ForumPosts.Count() <= 1 && IsNormalThread(thread))
{
db.ForumThreadLastReads.DeleteAllOnSubmit(db.ForumThreadLastReads.Where(x => x.ForumThreadID == thread.ForumThreadID).ToList());
db.ForumThreads.DeleteOnSubmit(thread);
db.SaveChanges();
return RedirectToAction("Index");
}
db.SaveChanges();
ResetThreadLastPostTime(threadID);
return RedirectToAction("Thread", new { id = threadID, page });
}
示例13: JoinFaction
public ActionResult JoinFaction(int id) {
if (Global.Account.FactionID != null) return Content("Already in faction");
if (Global.Account.Clan != null && Global.Account.Clan.FactionID != id) return Content("Must leave current clan first");
var db = new ZkDataContext();
Account acc = db.Accounts.Single(x => x.AccountID == Global.AccountID);
acc.FactionID = id;
Faction faction = db.Factions.Single(x => x.FactionID == id);
if (faction.IsDeleted && !(Global.Account.Clan != null && Global.Account.Clan.FactionID == id)) throw new ApplicationException("Cannot join deleted faction");
db.Events.InsertOnSubmit(PlanetwarsEventCreator.CreateEvent("{0} joins {1}", acc, faction));
db.SaveChanges();
return RedirectToAction("Index", "Factions");
}
示例14: StoreDbValue
private static void StoreDbValue(string varName, string value)
{
using (var db = new ZkDataContext())
{
var entry = db.MiscVars.FirstOrDefault(x => x.VarName == varName);
if (entry == null)
{
entry = new MiscVar() { VarName = varName };
db.MiscVars.Add(entry);
}
entry.VarValue = value;
db.SaveChanges();
}
}
示例15: UndeleteMission
public void UndeleteMission(int missionID, string author, string password)
{
var db = new ZkDataContext();
var prev = db.Missions.Where(x => x.MissionID == missionID).SingleOrDefault();
if (prev != null)
{
var acc = AuthServiceClient.VerifyAccountPlain(author, password);
if (acc == null) throw new ApplicationException("Invalid login name or password");
if (acc.AccountID != prev.AccountID && !acc.IsZeroKAdmin) throw new ApplicationException("You cannot undelete a mission from an other user");
prev.IsDeleted = false;
db.SaveChanges();
}
else throw new ApplicationException("No such mission found");
}