public static Domain.Race InsertRaceMaybe(string raceName) { string location = new StackFrame().GetMethod().DeclaringType.ToString(); _logger.OpenSection(location); string message = "Inserting new family '" + raceName + "'"; _logger.Info("Asking user: '******'"); Domain.Race returnRace = null; DialogResult dr = MessageBox.Show(message, "New family", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.Cancel) { _logger.Info("User cancelled; race will not be inserted."); } else { var insertedRace = new Domain.Race() { Name = raceName, Game = GlobalObjects.CurrentGame }; _logger.Info("Inserting race..."); _dbSession.Save(insertedRace); _logger.Info("Inserted race: " + insertedRace.ToString()); returnRace = insertedRace; } _logger.CloseSection(location); return(returnRace); }
private void dgvFusions_CellValueChanged(object sender, DataGridViewCellEventArgs e) { List <Domain.Fusion> allFusions; if (_cellChanged) { string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name; _logger.OpenSection(location); _logger.Info("Called with row index " + e.RowIndex + ", column index = " + e.ColumnIndex); Domain.Race race1 = this.dgvFusions.Rows[0].Cells[e.ColumnIndex].Tag as Domain.Race; Domain.Race race2 = this.dgvFusions.Rows[e.RowIndex].Cells[0].Tag as Domain.Race; var resultCell = this.dgvFusions.Rows[e.RowIndex].Cells[e.ColumnIndex]; Domain.Race race3 = null; if (resultCell.Value != null) { race3 = GlobalObjects.CurrentGame.Races. Where(x => x.Name == resultCell.Value.ToString()).FirstOrDefault(); if (race3 == null && resultCell.ToString() == GlobalObjects.ImpossibleToFuseRace.Name) { race3 = GlobalObjects.ImpossibleToFuseRace; } if (race3 == null) { race3 = _dbSession.CreateCriteria <Domain.Race>().List <Domain.Race>() .Where(x => x.Name == resultCell.Value.ToString()).FirstOrDefault(); if (race3 == null) { race3 = GlobalObjects.InsertRaceMaybe(resultCell.ToString()); } } } if (race3 == null && resultCell.Value != null) { _logger.Info("Insertion cancelled."); } else { using (var transaction = _dbSession.BeginTransaction()) { var currentFusion = _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>() .Where(x => x.IdRace1 == race2.Id && x.IdRace2 == race1.Id) .FirstOrDefault(); if (currentFusion == null) { currentFusion = _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>() .Where(x => x.IdRace1 == race1.Id && x.IdRace2 == race2.Id) .FirstOrDefault(); } if (currentFusion != null) { _logger.Info("Got fusion " + currentFusion.ToString()); if (race3 != null) { _logger.Info("Result of fusion will now be " + race3.ToString()); currentFusion.IdRace3 = race3.Id; _logger.Info("Saving fusion " + currentFusion.ToString()); _dbSession.Update(currentFusion); _logger.Info("Saved."); } else { _logger.Info("Fusion will be deleted from database."); _dbSession.Delete(currentFusion); _logger.Info("Deleted."); } } else { currentFusion = new Domain.Fusion(race1, race2, race3); _logger.Info("Creating new fusion " + currentFusion.ToString()); _dbSession.Save(currentFusion); _logger.Info("Created."); } transaction.Commit(); _logger.Info("Fusion saved."); } } _logger.CloseSection(location); } }