public void TestRemoveFisdItem()
        {
            var    tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);
            DbLink dbLink         = new DbLink(tempConnection);

            //создать финансовый инструмент
            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var resultFI = FinInstrument.FindId(dbLink, fin_instrument.ident);

            //ffd
            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = resultFI.fi_id,
                fif_id = 8,
            };

            if (FFD.Find(dbLink, resultFI.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, resultFI.fi_id, ffd.ds_id, ffd.fif_id);

            //dict_item
            dict_item dict_item = new dict_item()
            {
                fif_id = 8,
                key_v  = "RUB",
            };

            var resultDictItem = DictItem.FindId(dbLink, dict_item.key_v, dict_item.fif_id);

            //fisd_item
            fisd_item fisd_item = new fisd_item()
            {
                dat_from = new DateTime(2017, 08, 05),
                fisd_id  = ffdResult.fisd_id,
                val      = resultDictItem.key_v
            };

            if (FisdItem.FindId(dbLink, fisd_item.fisd_id, fisd_item.dat_from) == null)
            {
                FisdItem.Insert(dbLink, fisd_item);
                var one = FisdItem.FindId(dbLink, fisd_item.fisd_id, fisd_item.dat_from);
                FisdItem.Remove(dbLink, one.fisd_id, one.dat_from);
            }
            else
            {
                var one = FisdItem.FindId(dbLink, fisd_item.fisd_id, fisd_item.dat_from);
                FisdItem.Remove(dbLink, one.fisd_id, one.dat_from);
            }
        }
        private void Save(Dictionary <KeyValuePair <PortfolioPosition, Enum>, ScalarEnum> storage)
        {
            foreach (var x in storage)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    // найдем тип финансового инструмента
                    var    finIdent     = x.Key.Key.Ident;
                    var    finType      = x.Key.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);

                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fisd_id
                    ffd ffd = new ffd()
                    {
                        ds_id  = dataSource.ds_id,
                        fi_id  = finInstrument.fi_id,
                        fif_id = int.Parse(_mapping.GetAI(x.Key.Value))
                    };

                    if (FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
                    {
                        FFD.Insert(_dbLink, ffd);
                    }
                    ffd = FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id);
                    #endregion

                    #region dict_item
                    string key_v  = _mapping.GetTKE(x.Value.Dictionary.First().Value);
                    int    fif_id = int.Parse(_mapping.GetAI(x.Key.Value));

                    dict_item dict_item = new dict_item()
                    {
                        key_v  = key_v,
                        fif_id = fif_id,
                    };

                    var resultDictItem =
                        DictItem.FindId(_dbLink, dict_item.key_v, dict_item.fif_id);
                    #endregion

                    #region fisd_item
                    fisd_item fisd_item = new fisd_item()
                    {
                        dat_from = x.Value.Dictionary.First().Key,
                        fisd_id  = ffd.fisd_id,
                        val      = resultDictItem.key_v
                    };
                    #endregion

                    FisdItem.Insert(_dbLink, fisd_item);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }