/// <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(); }
/// <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(); } }
public Character Update(Character write) { if (write != null) { _db.Update(write); _db.SaveChanges(); } return(write); }
public Job Update(Job write) { if (write != null) { _db.Update(write); _db.SaveChanges(); } return(write); }
public Weapon Update(Weapon write) { if (write != null) { _db.Update(write); _db.SaveChanges(); } return(write); }
public Skill Update(Skill write) { if (write != null) { _db.Update(write); _db.SaveChanges(); } return(write); }
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(); }
/// <summary> /// Saves an entity of type T to the database. /// </summary> public void Save(T entity) { _context.Update(entity); _context.SaveChanges(); }
public async Task UpdateStatisticAsync(Statistic statistic) { _context.Update(statistic); await _context.SaveChangesAsync(); }