public void Load()
        {
            Name = "Members";
            //filter = "None";

            CodeProjectDatabase database = new CodeProjectDatabase();
            allMembers = database.GetMembers();

            var members = allMembers.Select(x => new CodeprojectMemberViewModel(x, gotoPageAction, this.DeleteMember)).ToList();
            Members = new ObservableCollection<CodeprojectMemberViewModel>(members);
        }
		public override bool OnContextItemSelected (IMenuItem item)
		{
			AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.MenuInfo;
			CodeProjectMember memberToDelete = members [info.Position];
			CodeProjectDatabase db = new CodeProjectDatabase ();
			db.DeleteMember (memberToDelete.Id);

			members = db.GetMembers ();
			ListAdapter = new CodeProjectMemberAdapter (this.Activity, members);

			return true;
		}
		public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, MonoTouch.Foundation.NSIndexPath indexPath)
		{
			if(editingStyle == UITableViewCellEditingStyle.Delete)
			{
				CodeProjectMember memberToDelete = MemberList [indexPath.Row];
				CodeProjectDatabase database = new CodeProjectDatabase ();
				database.DeleteMember (memberToDelete.Id);

				MemberList = database.GetMembers();
				tableView.ReloadData ();
			}
		}
		public static UITableViewCell FillCellWithMember(UITableViewCell cell, CodeProjectMember member) {
			(cell.ViewWithTag (100) as UILabel).Text = member.Name;
			(cell.ViewWithTag (101) as UILabel).Text = "Posts: " + (member.ArticleCount + member.BlogCount);
			(cell.ViewWithTag (102) as UILabel).Text = member.Reputation;

			CodeProjectDatabase database = new CodeProjectDatabase ();
			byte[] gravatar = database.GetGravatar (member.Id);
			if (gravatar != null) {

				UIImage image = UIImage.LoadFromData (NSData.FromArray (gravatar));
				(cell.ViewWithTag (105) as UIImageView).Image = image;

			}

			return cell;
		}
        public CodeprojectMemberViewModel(CodeProjectMember member, Action<string> gotoPageAction, Action<string> deleteMember)
        {
            this.GotoPageCommand = new ButtonCommandBinding<string>(gotoPageAction);
            this.DeleteMemberCommand = new ButtonCommandBinding<string>(deleteMember);
            this.member = member;

            var db = new CodeProjectDatabase();
            byte[] avatar = db.GetGravatar(this.member.Id);

            if (avatar != null)
            {
                BitmapImage bitmapImage = new BitmapImage();
                MemoryStream ms = new MemoryStream(avatar);
                bitmapImage.SetSource(ms);

                AvatarImage = bitmapImage;
            }
        }
		CodeProjectMember LoadGravatar() {

			var db = new CodeProjectDatabase ();
			byte[] avatar = db.GetGravatar(Member.Id);
			if (avatar != null) {

			} else {
				WebImageRetriever imageDownloader = new WebImageRetriever ();
				Task imageDownload = imageDownloader.GetImageStreamAsync (new Uri (Member.ImageUrl)).ContinueWith (t => {

					avatar = t.Result;
				});

				imageDownload.Wait ();
			}

			Member.Avatar = avatar;
			return Member;
		}
		public override Android.Views.View GetView (int position, Android.Views.View convertView, Android.Views.ViewGroup parent)
		{

			var view = convertView ?? activity.LayoutInflater.Inflate (
				Resource.Layout.CodeProjectMemberListItem, parent, false);
			var memberName = view.FindViewById<TextView> (Resource.Id.textViewMemberName);
			var memberReputation = view.FindViewById<TextView> (Resource.Id.textViewReputation);
			var memberPostCnt = view.FindViewById<TextView> (Resource.Id.textViewPostCnt);
			var memberIcon = view.FindViewById<ImageView> (Resource.Id.imageViewMemberImage);

			memberName.Text = list[position].Name;
			memberReputation.Text = list[position].Reputation;
			memberPostCnt.Text = "Posts: " + (list[position].ArticleCount + list[position].BlogCount);

			int textAppearanceLarge = TextAppearanceHeight (Android.Resource.Attribute.TextAppearanceLarge);
			int textAppearanceSmall = TextAppearanceHeight (Android.Resource.Attribute.TextAppearanceSmall);

			int bitmapSize = textAppearanceLarge + textAppearanceSmall;
			CodeProjectDatabase database = new CodeProjectDatabase ();
			byte[] gravatar = database.GetGravatar (list[position].Id);
			if (gravatar != null) {

				Bitmap image = BitmapFactory.DecodeByteArray (gravatar, 0, gravatar.Length);
				int maxSide = Math.Max (image.Height, image.Width);

				float scale = (float)bitmapSize / maxSide;

				memberIcon.SetImageBitmap (Bitmap.CreateScaledBitmap(image, 
					(int)Math.Ceiling(scale * image.Width), 
					(int)Math.Ceiling(scale * image.Height), 
					false));
				image.Recycle();
			}

			return view;
		}
        public void DeleteMember(string memberId)
        {
            CodeProjectDatabase db = new CodeProjectDatabase();
            db.DeleteMember(int.Parse(memberId));

            Load();
        }
//		public void OnLoaded() {
//		}

		public void SaveMember() {
			CodeProjectDatabase db = new CodeProjectDatabase ();
			db.AddMember (Member);
		}
		public void LoadMembers() {
			CodeProjectDatabase db = new CodeProjectDatabase ();
			members = db.GetMembers ();

			ListAdapter = new CodeProjectMemberAdapter (this.Activity, members);
		}
		void Refresh()
		{
			progressView.StartAnimating ();
			CodeProjectDatabase db = new CodeProjectDatabase ();
			MemberList = db.GetMembers();

			MemberListTable.Source = new CodeProjectMemberListDataSource(MemberList);
			MemberListTable.ReloadData ();

			RefreshFinished ();
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			progressView = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray);
			progressView.Center = new PointF (this.View.Frame.Width / 2, this.View.Frame.Height / 2);
			this.View.AddSubview (progressView);

			CodeProjectDatabase db = new CodeProjectDatabase ();
			MemberList = db.GetMembers();

			MemberListTable.Source = new CodeProjectMemberListDataSource(MemberList);

			MemberSearchBarController.SearchResultsWeakDataSource = this;
			MemberSearchBarController.WeakDelegate = this;

		}