public ActionResult AddDisadvantage(Disadvantage disadvantage) { var list = new DisadvantageDataAccess().FindAll <Disadvantage>(); disadvantage.Id = list.Count == 0 ? 1 : list.Last().Id + 1; disadvantage.Name = Request.Form["Name"]; disadvantage.Description = Request.Form["Description"]; disadvantage.Cost = int.Parse(Request.Form["Cost"]); disadvantage.Level = 0; disadvantage.LevelCap = int.Parse(Request.Form["LevelCap"]); if (disadvantage.LevelCap == 0) { disadvantage.LevelCap = int.MaxValue; } disadvantage.Formula = Request.Form["Formula"]; disadvantage.Types.AddRange(Request.Form.Where(x => x.Value.Contains("true")).Select(x => x.Key)); new DisadvantageDataAccess().InsertOne(disadvantage); return(RedirectToAction("Main", "Admin")); }
public bool Save([FromBody] JObject content) { try { dynamic data = JsonConvert.DeserializeObject <dynamic>(content.ToString()); Character character = new Character(); try { character = new CharacterDataAccess().FindOne(data.id); } catch { } character.Id = data.id; character.Name = data.name; character.Age = data.age == "" ? 0 : data.age; character.Height = data.height == "" ? 0 : data.height; character.Weight = data.weight == "" ? 0 : data.weight; character.MinimunStatusPoints = data.min_status; character.MaxPoints = data.max_points; character.CurrentPoints = data.current_points; character.Resources = data.resources; character.Description = data.description == "" ? "" : data.description; character.Status.Add("Strength", (int)data.strength); character.Status.Add("Dexterity", (int)data.dexterity); character.Status.Add("Intelligence", (int)data.intelligence); character.Status.Add("Health", (int)data.health); character.Status.Add("MaxLifePoints", (int)data.max_life_points); character.Status.Add("CurrentLifePoints", (int)data.current_life_points); character.Status.Add("Will", (int)data.will); character.Status.Add("Perception", (int)data.perception); character.Status.Add("MaxFatiguePoints", (int)data.max_fatigue_points); character.Status.Add("CurrentFatiguePoints", (int)data.current_fatigue_points); character.Status.Add("Speed", (int)data.speed); character.Status.Add("BasicMovement", (int)data.basic_movement); character.Status.Add("MaxCarryWeight", (int)data.max_carry_weight); character.Status.Add("CurrentCarryWeight", (int)data.current_carry_weight); foreach (var language in data.languages) { Language languageDatabase = new LanguageDataAccess().FindOne <Language>((int)language.id); languageDatabase.Level = language.level; character.Languages.Add(languageDatabase); } foreach (var skill in data.skills) { Skill skillDatabase = new SkillDataAccess().FindOne <Skill>((int)skill.id); skillDatabase.Level = skill.level; character.Skills.Add(skillDatabase); } foreach (var advantage in data.advantages) { Advantage advantageDatabase = new AdvantageDataAccess().FindOne <Advantage>((int)advantage.id); advantageDatabase.Level = advantage.level; character.Advantages.Add(advantageDatabase); } foreach (var disadvantage in data.disadvantages) { Disadvantage disadvantageDatabase = new DisadvantageDataAccess().FindOne <Disadvantage>((int)disadvantage.id); disadvantageDatabase.Level = disadvantage.level; character.Disadvantages.Add(disadvantageDatabase); } new CharacterDataAccess().InsertOne <Character>(character); } catch { return(false); } return(true); }