public SaveResult SaveMonsters(IEnumerable<Monster> dirtyMonsters) { var result = new SaveResult(); try { using (var batch = _monsterRepository.BeginBatch()) { foreach (var dirtyMonster in dirtyMonsters.Select(UpdateMonster)) { if (dirtyMonster.MonsterId == 0) batch.Add(dirtyMonster); else batch.Update(dirtyMonster); } batch.Commit(); result.Successful = true; } } catch (Exception ex) { result.Successful = false; result.Error = ex; } return result; }
public SaveResult SaveMonster(Monster dirtyMonster) { var monster = UpdateMonster(dirtyMonster); var result = new SaveResult(); try { if (monster.MonsterId == 0) _monsterRepository.Add(monster); else _monsterRepository.Update(monster); result.Successful = true; } catch (Exception ex) { result.Error = ex; result.Successful = false; } return result; }