public void SaveToDatabase() { using (LeattyContext DBContext = new LeattyContext()) { DB.Models.Guild UpdateGuild = DBContext.Guilds.Single(x => x.Id == GuildId); UpdateGuild.Id = GuildId; UpdateGuild.Leader = LeaderId; UpdateGuild.GP = GP; UpdateGuild.Logo = Logo; UpdateGuild.LogoColor = LogoColor; UpdateGuild.LogoBG = LogoBG; UpdateGuild.LogoBGColor = LogoBGColor; UpdateGuild.Rank1Title = RankTitles[0]; UpdateGuild.Rank2Title = RankTitles[1]; UpdateGuild.Rank3Title = RankTitles[2]; UpdateGuild.Rank4Title = RankTitles[3]; UpdateGuild.Rank5Title = RankTitles[4]; UpdateGuild.Capacity = Capacity; UpdateGuild.Notice = Notice; UpdateGuild.Signature = Signature; UpdateGuild.AllianceId = Alliance; DBContext.Entry <DB.Models.Guild>(UpdateGuild).State = System.Data.Entity.EntityState.Modified; DBContext.SaveChanges(); } }
public override void SaveToDatabase(MapleCharacter owner) { base.SaveToDatabase(owner); if (owner == null) { return; //delete is handled in base function } InventoryEquip dbActionEquip; using (LeattyContext dbContext = new LeattyContext()) { dbActionEquip = dbContext.InventoryEquips.FirstOrDefault(x => x.InventoryItemId == DbId); if (dbActionEquip == null) { dbActionEquip = new InventoryEquip { InventoryItemId = DbId }; dbContext.InventoryEquips.Add(dbActionEquip); dbContext.SaveChanges(); } } dbActionEquip.RemainingUpgradeCount = RemainingUpgradeCount; dbActionEquip.UpgradeCount = UpgradeCount; dbActionEquip.Str = Str; dbActionEquip.Dex = Dex; dbActionEquip.Int = Int; dbActionEquip.IncMhp = IncMhp; dbActionEquip.IncMmp = IncMmp; dbActionEquip.Pad = Pad; dbActionEquip.Mad = Mad; dbActionEquip.Pdd = Pdd; dbActionEquip.Mdd = Mdd; dbActionEquip.Acc = Acc; dbActionEquip.Eva = Eva; dbActionEquip.Speed = Speed; dbActionEquip.Jump = Jump; dbActionEquip.Durability = Durability; dbActionEquip.HammerApplied = HammersApplied; dbActionEquip.Enhancements = Enhancements; dbActionEquip.Diligence = Diligence; dbActionEquip.Potential1 = (short)Potential1; dbActionEquip.Potential2 = (short)Potential2; dbActionEquip.Potential3 = (short)Potential3; dbActionEquip.BonusPotential1 = (short)BonusPotential1; dbActionEquip.BonusPotential2 = (short)BonusPotential2; dbActionEquip.Socket1 = Socket1; dbActionEquip.Socket2 = Socket2; dbActionEquip.Socket3 = Socket3; dbActionEquip.CustomLevel = CustomLevel; dbActionEquip.CustomExp = CustomExp; dbActionEquip.PotentialState = (byte)PotentialState; using (LeattyContext dbContext = new LeattyContext()) { dbContext.Entry(dbActionEquip).State = EntityState.Modified; dbContext.SaveChanges(); } }
public void SetPic(string pic) { using (LeattyContext DBContext = new LeattyContext()) { byte[] key = saltshaker(32); string hashedPic = Functions.GetHMACSha512(pic, key); Account DbAccount = DBContext.Accounts.SingleOrDefault(x => x.Id == Id); DbAccount.Pic = hashedPic; DbAccount.PicKey = key.ByteArrayToString(nospace: true); DBContext.Entry <Account>(DbAccount).State = EntityState.Modified; DBContext.SaveChanges(); } }
/// <param name="owner">if equal to null, deletes the item from the database</param> public virtual void SaveToDatabase(MapleCharacter owner) { using (LeattyContext dbContext = new LeattyContext()) { if (owner == null) { if (InventoryType == MapleInventoryType.Equip) { InventoryEquip equipEntry = dbContext.InventoryEquips.FirstOrDefault(x => x.Id == DbId); if (equipEntry != null) { dbContext.InventoryEquips.Remove(equipEntry); } } InventoryItem entry = dbContext.InventoryItems.FirstOrDefault(x => x.Id == DbId); if (entry != null) { dbContext.InventoryItems.Remove(entry); } DbId = -1; } else { InventoryItem dbActionItem = null; if (DbId != -1) { dbActionItem = dbContext.InventoryItems.FirstOrDefault(x => x.Id == DbId); } if (dbActionItem == null) { dbActionItem = new InventoryItem(); dbContext.InventoryItems.Add(dbActionItem); dbContext.SaveChanges(); DbId = dbActionItem.Id; } dbActionItem.CharacterId = owner.Id; dbActionItem.ItemId = ItemId; dbActionItem.Position = Position; dbActionItem.Quantity = Quantity; dbActionItem.Source = Source; dbActionItem.Creator = Creator; dbActionItem.Flags = (short)Flags; dbContext.Entry(dbActionItem).State = System.Data.Entity.EntityState.Modified; } dbContext.SaveChanges(); } }
public static MapleGuild CreateGuild(string name, MapleCharacter leader) { foreach (MapleGuild g in Guilds.Values) { if (g.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) { return(null); } } using (LeattyContext DBContext = new LeattyContext()) { DB.Models.Guild InsertGuild = new DB.Models.Guild(); InsertGuild.Leader = leader.Id; InsertGuild.Name = name; DBContext.Guilds.Add(InsertGuild); Character DbChar = DBContext.Characters.SingleOrDefault(x => x.Id == leader.Id); DbChar.GuildContribution = 500; DbChar.AllianceRank = 5; DbChar.GuildRank = 1; DBContext.Entry <Character>(DbChar).State = System.Data.Entity.EntityState.Modified; DBContext.SaveChanges(); MapleGuild gld = new MapleGuild(); gld.GuildId = InsertGuild.Id; gld.LeaderId = leader.Id; gld.GP = 0; gld.Logo = 0; gld.LogoColor = 0; gld.Name = name; gld.Capacity = 10; gld.LogoBG = 0; gld.LogoBGColor = 0; gld.Notice = null; gld.Signature = 0; gld.Alliance = 0; Guilds.Add(gld.GuildId, gld); return(gld); } }
public override void SaveToDatabase(int chrId, bool detach = false) { using (LeattyContext DBContext = new LeattyContext()) { List <StolenSkill> stolenSkillsDatabase = DBContext.StolenSkills.Where(x => x.CharacterId == chrId).ToList(); for (int i = 0; i < StolenSkills.Length; i++) { StolenSkill stolenDatabaseSkill = stolenSkillsDatabase.Where(x => x.Index == i).FirstOrDefault(); if (stolenDatabaseSkill != null) //update record { stolenDatabaseSkill.SkillId = StolenSkills[i]; stolenDatabaseSkill.Chosen = IsChosenSkill(StolenSkills[i]); } else //insert new record { if (StolenSkills[i] > 0) //Only insert if skill id > 0, otherwise it isnt nesecary { StolenSkill insertStolenSkill = new StolenSkill(); insertStolenSkill.CharacterId = chrId; insertStolenSkill.SkillId = StolenSkills[i]; insertStolenSkill.Index = (byte)i; insertStolenSkill.Chosen = IsChosenSkill(StolenSkills[i]); DBContext.StolenSkills.Add(insertStolenSkill); if (detach) { DBContext.SaveChanges(); } } } if (detach) { DBContext.Entry <StolenSkill>(stolenDatabaseSkill).State = System.Data.Entity.EntityState.Detached; } } } }