ViewModel Example Code

public class EmployeeViewModel : DbMaintenanceViewModel<Employee>
{
        private int _employeeId;
        public int EmployeeId
        {
            get => _employeeId;
            set
            {
                if (_employeeId == value)
                    return;
                _employeeId = value;
                OnPropertyChanged(nameof(EmployeeId));
            }
        }

        private string _firstName;
        public string FirstName
        {
            get => _firstName;
            set
            {
                if (_firstName == value)
                    return;
                _firstName = value;
                OnPropertyChanged(nameof(FirstName));
            }
        }

        private string _lastName;
        public string LastName
        {
            get => _lastName;
            set
            {
                if (_lastName == value)
                    return;
                _lastName = value;
                OnPropertyChanged(nameof(LastName));
            }
        }

        [CanBeNull] private string _title;
        [CanBeNull]
        public string Title
        {
            get => _title;
            set
            {
                if (_title == value)
                    return;
                _title = value;
                OnPropertyChanged(nameof(Title));
            }
        }
(...)

 

private LookupDefinition<OrderLookup, Order> _ordersLookup; public LookupDefinition<OrderLookup, Order> OrdersLookupDefinition { get => _ordersLookup; set { if (_ordersLookup == value) return; _ordersLookup = value; OnPropertyChanged(nameof(OrdersLookupDefinition)); } }

        private AutoFillSetup _reportsToAutoFillSetup;
        public AutoFillSetup ReportsToAutoFillSetup
        {
            get => _reportsToAutoFillSetup;
            set
            {
                if (_reportsToAutoFillSetup == value)
                    return;

                _reportsToAutoFillSetup = value;
                OnPropertyChanged(nameof(ReportsToAutoFillSetup));
            }
        }

        private AutoFillValue _reportsTo;
        public AutoFillValue ReportsTo
        {
            get => _reportsTo;
            set
            {
                if (_reportsTo == value)
                    return;

                _reportsTo = value;
                OnPropertyChanged(nameof(ReportsTo));
            }
        }
        public EmployeeViewModel()
        {
            AddModifyCommand = new RelayCommand(OnAddModify);
(...)
        }
        protected override void Initialize()
        {
(...)
var ordersLookup = new LookupDefinition<OrderLookup, Order>(_lookupContext.Orders); ordersLookup.AddVisibleColumnDefinition(p => p.Order , p => p.OrderName); ordersLookup.Include(p => p.Customer) .AddVisibleColumnDefinition(p => p.Customer , p => p.CompanyName); OrdersLookupDefinition = ordersLookup; RegisterLookup(OrdersLookupDefinition, ViewModelInput);
base.Initialize(); }
        protected override void PopulatePrimaryKeyControls(Employee newEntity, PrimaryKeyValue primaryKeyValue)
        {
            EmployeeId = newEntity.EmployeeID;     
        }
         protected override void LoadFromEntity(Employee entity)
        {
            FirstName = entity.FirstName;
            LastName = entity.LastName;
            Title = entity.Title;
(...)
ReportsTo = entity.Supervisor.GetAutoFillValue(); }
        protected override Employee GetEntityData()
        {
            var employee = new Employee
            {
                EmployeeID = EmployeeId,
                FirstName = FirstName,
                LastName = LastName,
                FullName = $"{FirstName} {LastName}",
                Title = Title,
(...)
                SupervisorId = ReportsTo.GetEntity<Employee>().EmployeeID
            };

            return employee;
        }
        protected override void ClearData()
        {
            EmployeeId = 0;
            FirstName = LastName = string.Empty;
            Title = null;
(...) ReportsTo = null; }
        private void OnAddModify()
        {
            if (ExecuteAddModifyCommand() == DbMaintenanceResults.Success)
            {
                OrdersLookupDefinition.SetCommand(GetLookupCommand(LookupCommands.AddModify));
            }
        }