private void MigrateFavoritesDetails(FavoriteList favoriteList, string uid, string userEmailAddress, string source)
        {
            using (var cn = new SqlConnection(connectionString))
            {
                // Read all favorites lists
                var getListsSql = "SELECT email, quelle, liste, verzeichnungseinheit_id " +
                                  "FROM TempMigrationWorkspace " +
                                  "WHERE email = @email AND quelle = @source and liste = @liste";
                var da = new SqlDataAdapter(getListsSql, cn);
                da.SelectCommand.AddParameter("email", SqlDbType.NVarChar, userEmailAddress);
                da.SelectCommand.AddParameter("source", SqlDbType.NVarChar, source);
                da.SelectCommand.AddParameter("liste", SqlDbType.NVarChar, favoriteList.Name);
                var dt = new DataTable();
                da.Fill(dt);

                var existingItems = GetFavoritesContainedOnList(uid, favoriteList.Id).ToList();

                foreach (var row in dt.AsEnumerable())
                {
                    var veId         = Convert.ToInt32(row["verzeichnungseinheit_id"]);
                    var existingItem = existingItems.Cast <VeFavorite>().FirstOrDefault(l => l.VeId == veId);

                    if (existingItem == null)
                    {
                        var newItem = new VeFavorite
                        {
                            VeId = veId,
                            Kind = FavoriteKind.Ve
                        };

                        // Import the VE to this list
                        Log.Information("Inserting Ve {veId} to list {name}", veId, favoriteList.Name);
                        AddFavorite(uid, favoriteList.Id, newItem);
                    }
                }
            }
        }
        private VeFavorite CreateVeFavorite(int listId, SqlConnection cn, VeFavorite veFavorite)
        {
            using (var cmd = cn.CreateCommand())
            {
                cmd.CommandText = "INSERT INTO Favorite (List, Ve, Kind, CreatedAt) OUTPUT INSERTED.ID VALUES (@p1, @p2, @p3, @p4)";
                cmd.Parameters.Add(new SqlParameter
                {
                    Value         = listId,
                    ParameterName = "p1",
                    SqlDbType     = SqlDbType.Int
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    Value         = veFavorite.VeId,
                    ParameterName = "p2",
                    SqlDbType     = SqlDbType.Int
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    Value         = (int)FavoriteKind.Ve,
                    ParameterName = "p3",
                    SqlDbType     = SqlDbType.TinyInt
                });
                cmd.Parameters.Add(new SqlParameter
                {
                    Value         = veFavorite.CreatedAt,
                    ParameterName = "p4",
                    SqlDbType     = SqlDbType.DateTime
                });

                var id = Convert.ToInt32(cmd.ExecuteScalar());
                veFavorite.Id = id;
            }

            return(veFavorite);
        }