Esempio n. 1
0
        public async Task <IActionResult> AddIfNotExistsCharacter(CharacterToAddDTO characterToAdd)
        {
            if (await _characterRepository.CharacterExists(characterToAdd))
            {
                // 409 conflict seems to be most appropriate status code
                return(StatusCode(409));
            }

            var character = new Character
            {
                Name     = characterToAdd.Name,
                Realm    = characterToAdd.Realm,
                Region   = characterToAdd.Region,
                Class    = characterToAdd.Class,
                FullName = characterToAdd.FullName,
            };

            var addedCharacter = await _characterRepository.Add(character);

            return(StatusCode(201));
        }
Esempio n. 2
0
 public async Task <bool> CharacterExists(CharacterToAddDTO character)
 {
     return(await _context.Characters.AnyAsync(x => x.Name.Equals(character.Name) && x.Realm.Equals(character.Realm) && x.Region.Equals(character.Region)));
 }