public ActionResult DeleteCampaign(int campaignID) { viewbagofholdingEntities ORM = new viewbagofholdingEntities(); Campaign CampValidation = ORM.Campaigns.Find(campaignID); string userid = User.Identity.GetUserId(); if (CampValidation.DMUserID != userid) { return(RedirectToAction("Campaign", new { id = campaignID })); } Campaign campaignToDelete = ORM.Campaigns.Find(campaignID); List <Character> tempcharacters = ORM.Characters.Where(x => x.Campaign == campaignID).ToList(); foreach (Character c in tempcharacters) { c.Campaign = null; } ORM.Campaigns.Remove(campaignToDelete); ORM.SaveChanges(); return(RedirectToAction("Tracker")); }
public ActionResult CharacterSubmit(Character newCharacter) { viewbagofholdingEntities ORM = new viewbagofholdingEntities(); ORM.Characters.Add(newCharacter); ORM.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SaveCampaign(Campaign newCampaign) { viewbagofholdingEntities ORM = new viewbagofholdingEntities(); ORM.Campaigns.Add(newCampaign); ORM.SaveChanges(); return(RedirectToAction("Campaign", new { id = newCampaign.CampaignID })); }
public ActionResult DeleteCharacter(int charID) { viewbagofholdingEntities ORM = new viewbagofholdingEntities(); Character characterToDelete = ORM.Characters.Find(charID); if (User.Identity.IsAuthenticated) { ViewBag.User = User.Identity.GetUserId(); string userid = User.Identity.GetUserId(); if (characterToDelete.UserID != userid) { return(RedirectToAction("ViewCharacter", new { CharacterID = charID })); } } ORM.Characters.Remove(characterToDelete); ORM.SaveChanges(); return(RedirectToAction("Tracker")); }
public ActionResult RemoveCharacterFromCampaign(int charID, int campaignid) { viewbagofholdingEntities ORM = new viewbagofholdingEntities(); Campaign CampValidation = ORM.Campaigns.Find(campaignid); string userid = User.Identity.GetUserId(); if (CampValidation.DMUserID != userid) { return(RedirectToAction("Campaign", new { id = campaignid })); } Character characterToRemove = ORM.Characters.Find(charID); characterToRemove.Campaign = null; ORM.Entry(characterToRemove).State = System.Data.Entity.EntityState.Modified; ORM.SaveChanges(); ViewBag.ListOfCharacters = ORM.Characters.Where(x => x.Campaign == campaignid).ToList(); return(RedirectToAction("Campaign", new { id = campaignid })); }
public ActionResult LevelUp(Character UpdatedCharacter, string[] Proficiencies, string[] SpellsKnown, int hitdie) { double tempCon = double.Parse(UpdatedCharacter.Constitution.ToString()); int conmodifer = int.Parse(Math.Floor(tempCon / 2 - 5).ToString()); if (UpdatedCharacter.CharLevel < 20) { UpdatedCharacter.CharLevel += 1; } UpdatedCharacter.HitPoints += hitdie; string featuresString = ""; string characterLevel; for (int i = 1; i <= UpdatedCharacter.CharLevel; i++) { characterLevel = i.ToString(); HttpWebRequest dndFeatureApiRequest = WebRequest.CreateHttp($"http://www.dnd5eapi.co/api/classes/{Names[UpdatedCharacter.Class - 1]}/level/{characterLevel}"); dndFeatureApiRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"; HttpWebResponse dndFeatureApiResponse = (HttpWebResponse)dndFeatureApiRequest.GetResponse(); if (dndFeatureApiResponse.StatusCode == HttpStatusCode.OK) { StreamReader featureResponseData = new StreamReader(dndFeatureApiResponse.GetResponseStream()); string featuredata = featureResponseData.ReadToEnd(); JObject jsonFeatures = JObject.Parse(featuredata); for (int j = 0; j < jsonFeatures["features"].Count(); j++) { featuresString += jsonFeatures["features"][j]["name"] + ","; } } } UpdatedCharacter.Features = featuresString; characterLevel = (UpdatedCharacter.CharLevel).ToString(); HttpWebRequest dndSpellSlotApiRequest = WebRequest.CreateHttp($"http://www.dnd5eapi.co/api/classes/{Names[UpdatedCharacter.Class - 1]}/level/{characterLevel}"); dndSpellSlotApiRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"; HttpWebResponse dndSpellSlotApiResponse = (HttpWebResponse)dndSpellSlotApiRequest.GetResponse(); if (dndSpellSlotApiResponse.StatusCode == HttpStatusCode.OK) { StreamReader SpellSlotResponseData = new StreamReader(dndSpellSlotApiResponse.GetResponseStream()); string spellslotdata = SpellSlotResponseData.ReadToEnd(); JObject jsonSpellSlot = JObject.Parse(spellslotdata); if (jsonSpellSlot["spellcasting"] != null) { if (jsonSpellSlot["spellcasting"]["cantrips_known"] != null) { UpdatedCharacter.Cantrips = (int)jsonSpellSlot["spellcasting"]["cantrips_known"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_1"] != null) { UpdatedCharacter.SpellSlot1 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_1"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_2"] != null) { UpdatedCharacter.SpellSlot2 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_2"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_3"] != null) { UpdatedCharacter.SpellSlot3 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_3"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_4"] != null) { UpdatedCharacter.SpellSlot4 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_4"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_5"] != null) { UpdatedCharacter.SpellSlot5 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_5"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_6"] != null) { UpdatedCharacter.SpellSlot6 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_6"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_7"] != null) { UpdatedCharacter.SpellSlot7 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_7"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_8"] != null) { UpdatedCharacter.SpellSlot8 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_8"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_9"] != null) { UpdatedCharacter.SpellSlot9 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_9"]; } } } if (SpellsKnown != null) { string spells = ""; foreach (string spell in SpellsKnown) { spells += spell + ","; } UpdatedCharacter.SpellsKnown = spells; } string s = ""; foreach (string p in Proficiencies) { s += p + ","; } UpdatedCharacter.Proficiencies = s; viewbagofholdingEntities ORM = new viewbagofholdingEntities(); Character OldRecord = ORM.Characters.Find(UpdatedCharacter.CharID); OldRecord.HitPoints = UpdatedCharacter.HitPoints; OldRecord.Alignment = UpdatedCharacter.Alignment; OldRecord.CharLevel = UpdatedCharacter.CharLevel; OldRecord.SpellsKnown = UpdatedCharacter.SpellsKnown; OldRecord.Proficiencies = UpdatedCharacter.Proficiencies; OldRecord.Strength = UpdatedCharacter.Strength; OldRecord.Dexterity = UpdatedCharacter.Dexterity; OldRecord.Constitution = UpdatedCharacter.Constitution; OldRecord.Intelligence = UpdatedCharacter.Intelligence; OldRecord.Wisdom = UpdatedCharacter.Wisdom; OldRecord.Charisma = UpdatedCharacter.Charisma; OldRecord.Features = UpdatedCharacter.Features; OldRecord.SpellSlot1 = UpdatedCharacter.SpellSlot1; OldRecord.SpellSlot2 = UpdatedCharacter.SpellSlot2; OldRecord.SpellSlot3 = UpdatedCharacter.SpellSlot3; OldRecord.SpellSlot4 = UpdatedCharacter.SpellSlot4; OldRecord.SpellSlot5 = UpdatedCharacter.SpellSlot5; OldRecord.SpellSlot6 = UpdatedCharacter.SpellSlot6; OldRecord.SpellSlot7 = UpdatedCharacter.SpellSlot7; OldRecord.SpellSlot8 = UpdatedCharacter.SpellSlot8; OldRecord.SpellSlot9 = UpdatedCharacter.SpellSlot9; ORM.Entry(OldRecord).State = System.Data.Entity.EntityState.Modified; ORM.SaveChanges(); return(RedirectToAction("Tracker")); //OldRecord.Feats = UpdateItem.Feats; //OldRecord.Equipment = UpdateItem.Equipment; //OldRecord.Features = UpdateItem.Features; //OldRecord.Campaign = UpdateItem.Campaign; }
public ActionResult CharacterSubmit(Character newCharacter, string[] Proficiencies, string[] SpellsKnown) { string featuresString = ""; string characterLevel; for (int i = 1; i <= newCharacter.CharLevel; i++) { characterLevel = i.ToString(); HttpWebRequest dndFeatureApiRequest = WebRequest.CreateHttp($"http://www.dnd5eapi.co/api/classes/{Names[newCharacter.Class - 1]}/level/{characterLevel}"); dndFeatureApiRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"; HttpWebResponse dndFeatureApiResponse = (HttpWebResponse)dndFeatureApiRequest.GetResponse(); if (dndFeatureApiResponse.StatusCode == HttpStatusCode.OK) { StreamReader featureResponseData = new StreamReader(dndFeatureApiResponse.GetResponseStream()); string featuredata = featureResponseData.ReadToEnd(); JObject jsonFeatures = JObject.Parse(featuredata); for (int j = 0; j < jsonFeatures["features"].Count(); j++) { featuresString += jsonFeatures["features"][j]["name"] + ","; } } } newCharacter.Features = featuresString; characterLevel = newCharacter.CharLevel.ToString(); HttpWebRequest dndSpellSlotApiRequest = WebRequest.CreateHttp($"http://www.dnd5eapi.co/api/classes/{Names[newCharacter.Class - 1]}/level/{characterLevel}"); dndSpellSlotApiRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"; HttpWebResponse dndSpellSlotApiResponse = (HttpWebResponse)dndSpellSlotApiRequest.GetResponse(); if (dndSpellSlotApiResponse.StatusCode == HttpStatusCode.OK) { StreamReader SpellSlotResponseData = new StreamReader(dndSpellSlotApiResponse.GetResponseStream()); string spellslotdata = SpellSlotResponseData.ReadToEnd(); JObject jsonSpellSlot = JObject.Parse(spellslotdata); if (jsonSpellSlot["spellcasting"] != null) { if (jsonSpellSlot["spellcasting"]["cantrips_known"] != null) { newCharacter.Cantrips = (int)jsonSpellSlot["spellcasting"]["cantrips_known"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_1"] != null) { newCharacter.SpellSlot1 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_1"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_2"] != null) { newCharacter.SpellSlot2 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_2"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_3"] != null) { newCharacter.SpellSlot3 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_3"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_4"] != null) { newCharacter.SpellSlot4 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_4"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_5"] != null) { newCharacter.SpellSlot5 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_5"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_6"] != null) { newCharacter.SpellSlot6 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_6"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_7"] != null) { newCharacter.SpellSlot7 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_7"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_8"] != null) { newCharacter.SpellSlot8 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_8"]; } if (jsonSpellSlot["spellcasting"]["spell_slots_level_9"] != null) { newCharacter.SpellSlot9 = (int)jsonSpellSlot["spellcasting"]["spell_slots_level_9"]; } } } if (SpellsKnown != null) { string spells = ""; foreach (string spell in SpellsKnown) { spells += spell + ","; } newCharacter.SpellsKnown = spells; } string s = ""; foreach (string p in Proficiencies) { s += p + ","; } newCharacter.Proficiencies = s; //Session["t"] = newCharacter.Proficiencies; //Session["t2"] = newCharacter.Proficiencies[1]; viewbagofholdingEntities ORM = new viewbagofholdingEntities(); ORM.Characters.Add(newCharacter); ORM.SaveChanges(); return(RedirectToAction("Tracker")); }