|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfMvc.Views.Main;
using WpfMvc.Models.Main;
using WpfMvc.Entities;
using System.ComponentModel;
using System.Windows.Data;
using System.Collections.ObjectModel;
namespace WpfMvc.Controllers.Main
{
public class MainController: ControllerBase, IMainController
{
// Create few Persons at the startup
public override void Init()
{
//Model.Persons = new List<Person>()
//Model.Persons = new ObservableCollection<Person>()
Model.Persons = new NotifyingCollection<Person>()
{
new Person () { Code="001", Name = "David" , City = "Dublin"}
, new Person () { Code="003", Name = "Martin", City = "Prague"}
, new Person () { Code="005", Name = "Alain" , City = "Frankfurt" }
, new Person () { Code="007", Name = "Andy" , City = "Bratislava"}
};
}
public void Detail() // Creates new Person for editing, based on selected Entity
{
Model.Person = new Person(CollectionViewSource.GetDefaultView(Model.Persons).CurrentItem as Person);
}
public void Update()
{
Model.Persons // Updates the real Person nested in Model.Persons
.Where(p => p.Code == Model.Person.Code) // with properties according
.First() // to currently edited Model.Person
.Adjust(Model.Person);
}
public void Cancel()
{
Detail(); // Creates new Person instance for edint using selected Entity
}
public void Add()
{
Model.Persons.Add(new Person(Model.Person){ Code = Model.Person.Code + "1" });
}
public new IMainWindow View
{ // casts the base View to IMainWindow
get { return base.View as IMainWindow; }
set { base.View = value; }
}
public new IMainModel Model
{ // casting the base Model to IMainModel
get { return base.Model as IMainModel; }
set { base.Model = value; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.