|
using System;
using System.Windows.Input;
using Messengers;
namespace ViewModels
{
/// <summary>
/// A ViewModel for a view that allows a Customer to be modified
/// </summary>
public class CustomerEditViewModel : BaseViewModel
{
#region Private Fields
#endregion
#region Properties
/// <summary>
/// Just to save us casting the base class's IController to ICustomerController all the time...
/// </summary>
private ICustomerController CustomerController
{
get
{
return (ICustomerController)Controller;
}
}
#region Observable Properties
#endregion
#endregion
#region Commands
#region Command Relays
private RelayCommand cancelledCommand;
private RelayCommand saveCommand;
public ICommand CancelledCommand
{
get
{
return cancelledCommand ?? (cancelledCommand = new RelayCommand(() => ObeyCancelledCommand(), () => CanObeyCancelledCommand()));
}
}
public ICommand SaveCommand
{
get
{
return saveCommand ?? (saveCommand = new RelayCommand(() => ObeySaveCommand(), () => CanObeySaveCommand()));
}
}
#endregion // Command Relays
#region Command Handlers
/// <summary>
/// </summary>
/// <returns></returns>
private bool CanObeyCancelledCommand()
{
return true;
}
private void ObeyCancelledCommand()
{
CloseViewModel(false);
}
private bool CanObeySaveCommand()
{
return true;
}
private void ObeySaveCommand()
{
CustomerController.UpdateCustomer((CustomerEditViewData)ViewData);
CloseViewModel(true);
}
#endregion // Command Handlers
#endregion // Commands
#region Constructor
/// <summary>
/// A parameterless constructor is required for our design time data
/// </summary>
protected CustomerEditViewModel()
{ }
public CustomerEditViewModel(ICustomerController controller)
: this(controller, null)
{
}
public CustomerEditViewModel(ICustomerController controller, IView view)
: base(controller, view)
{
controller.Messenger.Register(MessageTypes.MSG_CUSTOMER_SELECTED_FOR_EDIT, new Action<Message>(HandleCustomerSelectedForEditMessage));
}
#endregion
/// <summary>
/// If somewhere someone selects a customer for editing and this Edit ViewModel is already
/// Editing that customer, then abort the message, and make the View active
/// </summary>
/// <param name="message"></param>
private void HandleCustomerSelectedForEditMessage(Message message)
{
CustomerListItemViewData customer = message.Payload as CustomerListItemViewData;
if (customer != null && customer.CustomerId == ((CustomerEditViewData)ViewData).CustomerId)
{
message.HandledStatus = MessageHandledStatus.HandledCompleted;
ActivateViewModel();
}
}
}
}
|
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.
Software developer par excellence,sometime artist, teacher, musician, husband, father and half-life 2 player (in no particular order either of preference or ability)
Started programming aged about 16 on a Commodore Pet.
Self-taught 6500 assembler - wrote Missile Command on the Pet (impressive, if I say so myself, on a text-only screen!)
Progressed to BBC Micro - wrote a number of prize-winning programs - including the best graphics application in one line of basic (it drew 6 multicoloured spheres viewed in perspective)
Trained with the MET Police as a COBOL programmer
Wrote platform game PooperPig which was top of the Ceefax Charts for a while in the UK
Did a number of software dev roles in COBOL
Progressed to Atari ST - learned 68000 assembler & write masked sprite engine.
Worked at Atari ST User magazine as Technical Editor - and was editor of Atari ST World for a while.
Moved on to IBM Mid range for work - working as team leader then project manager
Emigrated to Aus.
Learned RPG programming on the job (by having frequent coffee breaks with the wife!!)
Moved around a few RPG sites
Wrote for PC User magazine - was Shareware Magazine editor for a while.
Organised the first large-scale usage of the Internet in Australia through PC User magazine.
Moved from RPG to Delphi 1
Developed large applications in Delphi before moving on to VB .Net and C#
Became I.T. Manager - realised how boring paper pushing can be
And now I pretty much do .Net development in the daytime, while redeveloping PooperPig for the mobile market at night.