public void Edit()
        {
            FtpConnectionItemViewModel newItem;
            bool replace;
            var  ftpconn = SelectedItem as FtpConnectionItemViewModel;

            if (ftpconn != null)
            {
                newItem = ftpconn.Clone();
                replace = true;
            }
            else if (SelectedItem is NewConnectionPlaceholderViewModel)
            {
                var model = new FtpConnection
                {
                    Port            = 21,
                    ConnectionImage = (int)ConnectionImage.Fat,
                };
                newItem = new FtpConnectionItemViewModel(model);
                replace = false;
            }
            else
            {
                throw new NotSupportedException();
            }

            var dialog = new NewConnectionDialog(Items.OfType <FtpConnectionItemViewModel>().Select(item => item.Name).ToList(), newItem);

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            newItem.Name = newItem.Name.Trim();
            if (newItem.Username != null)
            {
                newItem.Username = newItem.Username.Trim();
            }
            if (newItem.Password != null)
            {
                newItem.Password = newItem.Password.Trim();
            }
            if (replace)
            {
                Items.Remove(ftpconn);
            }

            var i = 0;

            while (i < Items.Count - 1 && String.Compare(newItem.Name, Items[i].Name, StringComparison.InvariantCultureIgnoreCase) == 1)
            {
                i++;
            }
            Items.Insert(i, newItem);
            Save(newItem);
            SelectedItem = newItem;
        }
 private void Save(FtpConnectionItemViewModel connection)
 {
     if (connection == null)
     {
         return;
     }
     using (var db = _dbContext.Open())
     {
         db.Persist(connection.Model);
     }
 }
 private void Save(FtpConnectionItemViewModel connection)
 {
     if (connection == null) return;
     using (var db = _dbContext.Open())
     {
         db.Persist(connection.Model);
     }
 }
        public void Edit()
        {
            FtpConnectionItemViewModel newItem;
            bool replace;
            var ftpconn = SelectedItem as FtpConnectionItemViewModel;
            if (ftpconn != null)
            {
                newItem = ftpconn.Clone();
                replace = true;
            } 
            else if (SelectedItem is NewConnectionPlaceholderViewModel)
            {
                var model = new FtpConnection
                                {
                                    Port = 21,
                                    ConnectionImage = (int) ConnectionImage.Fat,
                                };
                newItem = new FtpConnectionItemViewModel(model);
                replace = false;
            }
            else
            {
                throw new NotSupportedException();
            }

            var dialog = new NewConnectionDialog(Items.OfType<FtpConnectionItemViewModel>().Select(item => item.Name).ToList(), newItem);
            if (dialog.ShowDialog() != true) return;

            newItem.Name = newItem.Name.Trim();
            if (newItem.Username != null) newItem.Username = newItem.Username.Trim();
            if (newItem.Password != null) newItem.Password = newItem.Password.Trim();
            if (replace) Items.Remove(ftpconn);

            var i = 0;
            while (i < Items.Count - 1 && String.Compare(newItem.Name, Items[i].Name, StringComparison.InvariantCultureIgnoreCase) == 1) i++;
            Items.Insert(i, newItem);
            Save(newItem);
            SelectedItem = newItem;
        }