public async Task <IActionResult> Create([Bind(
                                                      "ID," +
                                                      "Name," +
                                                      "Species," +
                                                      "Gender," +
                                                      "Faction," +
                                                      "Homeworld," +
                                                      "Background," +
                                                      "Class," +
                                                      "PartialClasses," +
                                                      "Strength," +
                                                      "StrengthModifierBonus," +
                                                      "Dexterity," +
                                                      "DexterityModifierBonus," +
                                                      "Constitution," +
                                                      "ConstitutionModifierBonus," +
                                                      "Intelligence," +
                                                      "IntelligenceModifierBonus," +
                                                      "Wisdom," +
                                                      "WisdomModifierBonus," +
                                                      "Charisma" +
                                                      "CharismaModifierBonus,")] Character character)
        {
            if (ModelState.IsValid)
            {
                _context.Add(character);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(character));
        }
Beispiel #2
0
        public async Task <ActionResult <CharacterItem> > PostCharacterItem(CharacterItem item)
        {
            _context.CharacterItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCharacterItem), new { id = item.Id }, item));
        }
Beispiel #3
0
        public async Task <IActionResult> PutCharacterItem(long id, CharacterItem characterItem)
        {
            if (id != characterItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(characterItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CharacterItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Character> > PostCharacter(Character character)
        {
            _context.Characters.Add(character);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCharacter), new { id = character.Id }, character));
        }
        public async Task <IActionResult> Post([FromBody] string name)
        {
            var character = new Character(name);

            _context.Characters.Add(character);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetChar", new { id = character.Id }, character));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Url,Gender,Culture,Born,Died,Father,Mother,Spouse")] Character character)
        {
            if (ModelState.IsValid)
            {
                _context.Add(character);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(character));
        }
        public async Task <IActionResult> Create([FromBody] FullCharacter character)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Character newCharacter = character.ToCharacter();

            _db.Characters.Add(newCharacter);
            await _db.SaveChangesAsync();

            return(Created(newCharacter.Id.ToString(),
                           new HitPointsResult(newCharacter)));
        }
Beispiel #8
0
        public void Delete(int id)
        {
            var character = _context.Characters.Find(id);

            _context.Characters.Remove(character);
            _context.SaveChangesAsync();
        }
Beispiel #9
0
 public static async Task SaveResidence(ResidenceEntity residence)
 {
     using (var context = new CharacterContext())
     {
         residence.Save(context);
         await context.SaveChangesAsync();
     }
 }
Beispiel #10
0
 public static async Task SavePlayer(Player player)
 {
     using (var context = new CharacterContext())
     {
         player.Save(context);
         await context.SaveChangesAsync();
     }
 }
 public async Task Save(IEnumerable <ISaveCharacter> entities)
 {
     await using var context = new CharacterContext(config);
     foreach (ISaveCharacter entity in entities)
     {
         entity.Save(context);
     }
     await context.SaveChangesAsync();
 }
Beispiel #12
0
        private async Task SetHP(int hp, int tempHP)
        {
            var character = await _db.Characters.SingleAsync();

            character.CurHitPoints  = hp;
            character.TempHitPoints = tempHP;
            _db.Characters.Update(character);
            await _db.SaveChangesAsync();
        }
Beispiel #13
0
    public async Task <int> AddQuoteToCharacterAsync(int characterId, string quoteText)
    {
        var character = GetCharacter(characterId);

        if (character is null)
        {
            return(0);
        }
        character.AddQuote(quoteText);
        return(await _context.SaveChangesAsync());
    }
Beispiel #14
0
        public static async Task CreateCharacter(Model.Character character, IEnumerable <ItemEntity> items)
        {
            using (var context = new CharacterContext())
            {
                context.Character.Add(character);
                foreach (var item in items)
                {
                    item.Save(context);
                }

                await context.SaveChangesAsync();
            }
        }
 //Look into asyncronous programming to make my code more efficient.
 public void SaveChangesAsync()
 {
     if (_context != null)
     {
         _context.SaveChangesAsync();
     }
     if (_spellsContext != null)
     {
         _spellsContext.SaveChangesAsync();
     }
     if (_itemsContext != null)
     {
         _itemsContext.SaveChangesAsync();
     }
     if (_playableClassContext != null)
     {
         _playableClassContext.SaveChangesAsync();
     }
     if (_raceContext != null)
     {
         _raceContext.SaveChangesAsync();
     }
 }
 public async Task Save(Action <CharacterContext> action)
 {
     using var context = new CharacterContext(config);
     action.Invoke(context);
     await context.SaveChangesAsync();
 }
 public async Task Save(ISaveCharacter entity)
 {
     await using var context = new CharacterContext(config);
     entity.Save(context);
     await context.SaveChangesAsync();
 }