private void Sync(ClientKit kit, NpgsqlConnection dbConnection) { var isExistClient = DbPg.GetExistNumClient(kit.Client.Set10Guid); var cardComposition = kit.Cards.Select(card => new CardsCompositions(card, DbPg.GetExistCardByGuid(card, dbConnection), DbPg.GetExistCardByNumCard(card, dbConnection))).ToList(); dbConnection = DbPg.GetConnection(dbConnection); if (!dbConnection.FullState.Equals(ConnectionState.Open)) { dbConnection.Open(); } var transaction = dbConnection.BeginTransaction(); try { var bAccounts = DbPg.GetBonusAccounts(kit.Client.BonusAccountId, dbConnection); if (bAccounts == null || bAccounts.Count == 0) { BonusAccounts(kit.Client, transaction, dbConnection); } Client(kit.Client, isExistClient, transaction, dbConnection); if (cardComposition.Any()) { Cards(kit.Client, cardComposition, transaction, dbConnection); } transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception("Sync kit exception.", e); } }
public void Go() { var dbConnection = DbPg.GetConnection(); var dbMsConnection = DbMs.GetConnection(); var clients = DbMs.AllChangedClients(); foreach (var cli in clients) { var kit = DbMs.GetClientFullInfo(cli, dbMsConnection); try { Sync(kit, dbConnection); DbMs.UpdateClientKitIsLoadToSet10(cli.Uid, true); } catch (Exception) { } } }