public HomeViewModel() { _localRepository = new LocalRepository(); Employee = new Employee(); SaveEmployeeCommand = new Command(async () => { var isSaved = await _localRepository.SaveEmployeeAsync(_employee); if (isSaved) { MessagingCenter.Send(this, "Message", "The employee was saved successfully!"); } else { MessagingCenter.Send(this, "Message", "The employee was not saved!"); } }); GetEmployeeCommand = new Command(async () => { Employee = await _localRepository.GetEmployeeAsync(); if (_employee == null) { MessagingCenter.Send(this, "Message", "The employee was not retrieved!"); } else { MessagingCenter.Send(this, "Message", "The employee was retrieved successfully!"); } }); }
/// <summary> /// Save the employee in parameter to local phone storage. /// </summary> /// <param name="employee"></param> /// <returns></returns> public async Task<bool> SaveEmployeeAsync(Employee employee) { var textJson = JsonConvert.SerializeObject(employee); return await DependencyService.Get<ISaveAndLoadText>().SaveTextAsync(textJson); }