public Quest CreateQuest(string name, string desc, int questType, int scenarioID, System.DateTime dueDate, int points, Nullable <decimal> latitude = null, Nullable <decimal> longitude = null) { using (var trs = transactionScopeProvider.CreateTransactionScope()) { var quest = new Quest() { Name = name, Description = desc, Completed = false, QuestTypeID = questType, ScenarioID = scenarioID, DueDate = dueDate, Latitude = latitude, Longitude = longitude, Points = points }; questRepository.Add(quest); questRepository.SaveChanges(); TryToDoMotorllaMarker(quest); trs.Complete(); return(quest); } }
public void AddQuest() { var questDetailViewModel = new QuestDetailViewModel(new Quest()); var newDialog = new AddQuestDialog { DataContext = questDetailViewModel }; newDialog.ShowDialog(); if (newDialog.DialogResult == true) { _questRepository.Add(questDetailViewModel.Quest); _questRepository.SaveChanges(); RefreshQuests(); } }
private string _handleQuestMessage(string[] sections) { string response = null; QuestDefinition entity; int romId; QuestDefinition match; switch (sections[1]) { case "SAVE": entity = new QuestDefinition(sections[2], 2); match = _questRepository.GetByRomId(entity.RomId); if (match != null) { match.Gold = entity.Gold; match.Level = entity.Level; match.MinLevel = entity.MinLevel; match.QuestChain = entity.QuestChain; match.RewardCategory = entity.RewardCategory; match.RewardSubCategory = entity.RewardSubCategory; match.StarterId = entity.StarterId; match.EnderId = entity.EnderId; match.TP = entity.TP; match.XP = entity.XP; //need to loop through rewards, matching up and copying //match.Rewards = entity.XP; _questRepository.Update(match); } else { _questRepository.Add(entity); } break; case "SAVEFROMAQB": entity = new QuestDefinition(sections[2], 2); match = _questRepository.GetByRomId(entity.RomId); if (match != null) { if ((entity.Gold > 0) && (match.Gold < 1)) { match.Gold = entity.Gold; } if ((entity.Level > 0) && (match.Level < 1)) { match.Level = entity.Level; } if ((entity.MinLevel > 0) && (match.MinLevel < 1)) { match.MinLevel = entity.MinLevel; } if ((entity.StarterId > 0) && (match.StarterId < 1)) { match.StarterId = entity.StarterId; } if ((entity.EnderId > 0) && (match.EnderId < 1)) { match.EnderId = entity.EnderId; } if ((entity.TP > 0) && (match.TP < 1)) { match.TP = entity.TP; } if ((entity.XP > 0) && (match.XP < 1)) { match.XP = entity.XP; } //need to loop through rewards, matching up and copying //match.Rewards = entity.XP; _questRepository.Update(match); } else { _questRepository.Add(entity); } break; case "DELETE": romId = Convert.ToInt32(sections[2]); _questRepository.Delete(romId); break; case "GET": romId = Convert.ToInt32(sections[2]); entity = _questRepository.GetByRomId(romId); if (entity != null) { response = entity.ToDelimitedString(1); } else { response = QuestDefinition.GetNullDefinitionString(1); } break; case "BOOKUPDATE": string[] questData = sections[2].Split((char)2); int i = 0; romId = Convert.ToInt32(questData[i]); i++; string qName = questData[i]; i++; int lvl = Convert.ToInt32(questData[i]); i++; int starterId = Convert.ToInt32(questData[i]); i++; int enderId = Convert.ToInt32(questData[i]); i++; int gold = Convert.ToInt32(questData[i]); i++; int xp = Convert.ToInt32(questData[i]); i++; int tp = Convert.ToInt32(questData[i]); bool isUpdate = true; entity = _questRepository.GetByRomId(romId); if (entity == null) { entity = new QuestDefinition() { RomId = romId, Name = qName, Level = lvl, StarterId = starterId, EnderId = enderId, Gold = gold, XP = xp, TP = tp }; isUpdate = false; } else { entity.Name = qName; entity.StarterId = starterId; entity.EnderId = enderId; entity.Level = lvl; entity.MinLevel = lvl - 3; if (entity.MinLevel < 1) { entity.MinLevel = 0; } entity.Gold = gold; entity.XP = xp; entity.TP = tp; } if ((entity.Rewards.Count < 1) && (!string.IsNullOrEmpty(sections[3]))) { string[] rewards = sections[3].Split((char)2); foreach (string rewardString in rewards) { if (string.IsNullOrEmpty(rewardString)) { continue; } try { QuestReward reward = new QuestReward(rewardString, 3, _itemRepository); if ((reward.RewardType != null) || (reward.Item != null)) { entity.Rewards.Add(reward); reward.Quest = entity; } } catch { } } //IRepository<QuestReward> rewardRep = new Repository<QuestReward>(_factory); _questRepository.Update(entity); //foreach (QuestReward reward in entity.Rewards) //{ // rewardRep.SaveOrUpdate(reward); //} } break; } return(response); }