Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task UpdateCharacterAsync(Character character)
        {
            // If the character does not exist in the database, abort
            if (await _context.Characters.CountAsync(c => c.Id.Equals(character.Id)) <= 0)
            {
                return;
            }

            var dbChar = await _context.Characters.Where(x => x.Id.Equals(character.Id))
                         .Include(x => x.Statistics).ThenInclude(x => x.Statistic)
                         .Include(x => x.Statistics).ThenInclude(x => x.StatisticValue)
                         .Include(x => x.EffectMappings).ThenInclude(x => x.Effect).ThenInclude(x => x.StatisticEffects).ThenInclude(x => x.Statistic)
                         .Include(x => x.EffectMappings).ThenInclude(x => x.Effect).ThenInclude(x => x.StatisticEffects).ThenInclude(x => x.StatisticValue)
                         .FirstOrDefaultAsync();

            _mapper.Map <Character, CharacterDto>(character, dbChar);

            if (dbChar.EffectMappings == null)
            {
                dbChar.EffectMappings = new List <EffectMapping>();
            }
            else
            {
                dbChar.EffectMappings.Clear();
            }

            foreach (var effect in character.Effects)
            {
                var effectDto = _mapper.Map <EffectDto>(effect);
                dbChar.EffectMappings.Add(new EffectMapping {
                    Effect = effectDto, Character = dbChar
                });
            }

            _context.Update(dbChar);

            if (character.Active)
            {
                var user = await _context.Users.FirstOrDefaultAsync(x => x.UserIdentifier == character.UserIdentifier);

                if (user != null)
                {
                    user.ActiveCharacter = dbChar;
                    _context.Update(user);
                }
                else
                {
                    await _context.AddAsync(new User { UserIdentifier = character.UserIdentifier, ActiveCharacter = dbChar });
                }
            }

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves an entity of type T to the database.
        /// </summary>
        public void Save(T entity)
        {
            _semaphore.Wait();

            try
            {
                _context.Update(entity);
                _context.SaveChanges();
            }
            finally
            {
                _semaphore.Release();
            }
        }
Ejemplo n.º 3
0
 public Character Update(Character write)
 {
     if (write != null)
     {
         _db.Update(write);
         _db.SaveChanges();
     }
     return(write);
 }
Ejemplo n.º 4
0
 public Job Update(Job write)
 {
     if (write != null)
     {
         _db.Update(write);
         _db.SaveChanges();
     }
     return(write);
 }
Ejemplo n.º 5
0
 public Weapon Update(Weapon write)
 {
     if (write != null)
     {
         _db.Update(write);
         _db.SaveChanges();
     }
     return(write);
 }
Ejemplo n.º 6
0
 public Skill Update(Skill write)
 {
     if (write != null)
     {
         _db.Update(write);
         _db.SaveChanges();
     }
     return(write);
 }
Ejemplo n.º 7
0
        public async Task UpdateEffectAsync(Effect effect)
        {
            // If it doesn't exist in the DB, abort
            if (await _context.Effects.CountAsync(c => c.Id.Equals(effect.Id)) <= 0)
            {
                return;
            }

            var dto = await _context.Effects.FirstOrDefaultAsync(x => x.Id.Equals(effect.Id));

            _mapper.Map <Effect, EffectDto>(effect, dto);
            dto.EffectMappings = await _context.Set <EffectMapping>().Where(x => x.EffectId.Equals(effect.Id)).ToListAsync();

            _context.Update(dto);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Saves an entity of type T to the database.
 /// </summary>
 public void Save(T entity)
 {
     _context.Update(entity);
     _context.SaveChanges();
 }
Ejemplo n.º 9
0
 public async Task UpdateStatisticAsync(Statistic statistic)
 {
     _context.Update(statistic);
     await _context.SaveChangesAsync();
 }