private void Save(object x)
        {
            if (IsEditMode)
            {
                if (ProjectsDataService.UpdateProject(Project))
                {
                    Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "Project details updated!");
                }
                else
                {
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error saving project in database");
                }
            }
            else
            {
                if (ProjectsDataService.AddNewProject(Project))
                {
                    //Notify Mediator that the project was added
                    Mediator.NotifyColleagues(ViewModelMessages.NewProjectAdded, Project);
                    //also send a notification to user
                    Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "New project added!");

                    //clear the fields in the View
                    Project = new WPFDisciples.Backend.ProjectDetails();
                }
                else
                {
                    //Notify Mediator there was an error
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error saving project in database");
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dispatcher">The dispatcher object of the view</param>
        public ProjectListViewModel(Dispatcher dispatcher)
        {
            this.dispatcher = dispatcher;

            //Register to the ShowListOfProjects message because this means that we added a new project and that we should add it to the list
            Mediator.Register(x =>
                              //We could have got the data from the database, but the mediator will give us the new object and we can simple add it to the list and let ListBinding work it's magic :)
                              projects.Add((WPFDisciples.Backend.ProjectDetails)x),
                              ViewModelMessages.NewProjectAdded);


            OpenUrl = x => dispatcher.BeginInvoke(
                (Action) delegate
            {
                try
                {
                    System.Diagnostics.Process.Start((string)x);
                }
                catch
                {
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error opening URL");
                }
            }, DispatcherPriority.Background, null);

            DeleteProject = new SimpleCommand
            {
                ExecuteDelegate = x =>
                {
                    var proj = (WPFDisciples.Backend.ProjectDetails)x;
                    if (ProjectsDataService.DeleteProject(proj))
                    {
                        Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "Project deleted!");
                        Projects.Remove(proj);
                    }
                    else
                    {
                        Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Cannot delete project!");
                    }
                }
            };

            //Switch the view name. This will be picked up by binding and the view will change accordingly
            SelectView = x => CurrentView = (string)x;
        }
 /// <summary>
 /// Loads the data for the View
 /// </summary>
 public void LoadData()
 {
     //use dispatcher to do this when the dispatcher is not busy loading UI. In a real world app this should be done in a sepearte thread.
     dispatcher.BeginInvoke((Action) delegate
     {
         var data = ProjectsDataService.GetProjects();
         if (data != null)
         {
             foreach (var item in data)
             {
                 projects.Add(item);
             }
         }
         else
         {
             //Notify mediator there was an error
             Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Cannot get the list of projects from DB");
         }
     }, DispatcherPriority.Background, null);
 }