public async Task <Character> GetCharacterAsync(string characterId)
        {
            using (var factory = _dbContextHelper.GetFactory())
            {
                var dbContext = factory.GetDbContext();

                var storeCharacter = await dbContext.Characters
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(e => e.Id == characterId);

                if (storeCharacter != null)
                {
                    return(storeCharacter);
                }

                var character = await _censusCharacter.GetCharacter(characterId);

                if (character == null)
                {
                    return(null);
                }

                var censusEntity = ConvertToDbModel(character);

                dbContext.Add(censusEntity);
                await dbContext.SaveChangesAsync();

                return(censusEntity);
            }
        }
        public async Task <Character> GetCharacterAsync(string characterId)
        {
            try
            {
                var character = await _censusCharacter.GetCharacter(characterId);

                if (character == null)
                {
                    return(null);
                }

                var censusEntity = ConvertToDbModel(character);

                return(censusEntity);
            }
            catch
            {
                // TODO: add logging to this service
                return(null);
            }

            /*
             *
             * using (var factory = _dbContextHelper.GetFactory())
             * {
             *  var dbContext = factory.GetDbContext();
             *
             *  //IQueryable<Character> characterQuery = dbContext.Characters.Where(e => e.Id == characterId);
             *
             *  var storeCharacter =  await dbContext.Characters
             *                                  .AsNoTracking()
             *                                  .FirstOrDefaultAsync(e => e.Id == characterId);
             *
             *  if (storeCharacter != null)
             *  {
             *      return storeCharacter;
             *  }
             *
             *  var character = await _censusCharacter.GetCharacter(characterId);
             *
             *  if (character == null)
             *  {
             *      return null;
             *  }
             *
             *  var censusEntity = ConvertToDbModel(character);
             *
             *  dbContext.Add(censusEntity);
             *  await dbContext.SaveChangesAsync();
             *
             *  return censusEntity;
             * }
             */
        }
Exemple #3
0
        private async Task <Outfit> ResolveOutfitDetailsAsync(Outfit outfit, Character member)
        {
            if (member != null)
            {
                outfit.WorldId   = member.WorldId;
                outfit.FactionId = member.FactionId;
            }
            else
            {
                var leader = await _censusCharacter.GetCharacter(outfit.LeaderCharacterId);

                outfit.WorldId   = leader.WorldId;
                outfit.FactionId = leader.FactionId;
            }

            return(outfit);
        }
        public async Task <Character> GetCharacterAsync(string characterId)
        {
            try
            {
                var character = await _censusCharacter.GetCharacter(characterId);

                if (character == null)
                {
                    return(null);
                }

                var censusEntity = ConvertToDbModel(character);

                return(censusEntity);
            }
            catch
            {
                // TODO: add logging to this service
                return(null);
            }
        }