/// <summary> /// Initializes a new instance of the MainViewModel class. /// The class gets an instance of The DataAccessService /// </summary> public MainViewModel(IDataAccessService servPxy) { _serviceProxy = servPxy; Employees = new ObservableCollection<EmployeeInfo>(); EmpInfo = new EmployeeInfo(); ReadAllCommand = new RelayCommand(GetEmployees); SaveCommand = new RelayCommand<EmployeeInfo>(SaveEmployee); SearchCommand = new RelayCommand(SearchEmployee); SendEmployeeCommand = new RelayCommand<EmployeeInfo>(SendEmployeeInfo); ReceiveEmployeeInfo(); }
/// <summary> /// Method to Save Employees. Once the Employee is added in the database /// it will be added in the Employees observable collection and Property Changed will be raised /// </summary> /// <param name="emp"></param> void SaveEmployee(EmployeeInfo emp) { EmpInfo.EmpNo = _serviceProxy.CreateEmployee(emp); if(EmpInfo.EmpNo!=0) { Employees.Add(EmpInfo); RaisePropertyChanged("EmpInfo"); } }
/// <summary> /// The method to send the selected Employee from the DataGrid on UI /// to the View Model /// </summary> /// <param name="emp"></param> void SendEmployeeInfo(EmployeeInfo emp) { if(emp!=null) { Messenger.Default.Send<MessageCommunicator>(new MessageCommunicator() { Emp = emp }); } }
public int CreateEmployee(EmployeeInfo Emp) { context.EmployeeInfoes.Add(Emp); context.SaveChanges(); return Emp.EmpNo; }