public void DeleteIndex(StockIndex stockIndex)
        {
            using (StockDataEntities context = new StockDataEntities())
            {
                StockIndex existingIndex = context.StockIndexes
                    .Where(i => String.Compare(i.IndexName, stockIndex.IndexName, true) == 0).SingleOrDefault();

                if (existingIndex != null)
                {
                    context.StockIndexes.Remove(existingIndex);

                    context.SaveChanges();
                }

            }
        }
        private void lvIndexes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.lvIndexes.SelectedItem != null)
            {
                StockIndex index = this.lvIndexes.SelectedItem as StockIndex;
                this._selectedIndex = index;

                this.txtName.Text = index.IndexName;
                this.txtDesc.Text = index.Description;
                this.cbCountry.SelectedValue = index.CountryCode;

                this.lvComponents.ItemsSource = this._symbolRepository.GetIndexComponents(index.IndexName);
                if (this.lvComponents.Items.Count > 0)
                    this.tbComponents.Text = string.Format("Total {0} components", this.lvComponents.Items.Count);
                else
                    this.tbComponents.Text = "";
            }
        }
        public void UpdateStockIndex(StockIndex stockIndex)
        {
            using (StockDataEntities context = new StockDataEntities())
            {
                StockIndex existingIndex = context.StockIndexes
                    .Where(i => String.Compare(i.IndexName, stockIndex.IndexName, true) == 0).SingleOrDefault();

                if (existingIndex != null)
                {
                    existingIndex.Description = stockIndex.Description;
                }
                else
                {
                    context.StockIndexes.Add(stockIndex);
                }

                context.SaveChanges();
            }
        }