示例#1
0
        private async void submitButton_Click(object sender, RoutedEventArgs e)
        {
            var employeeContact = new Models.EmployeeContact()
            {
                EmailAddress = emailAddress.Text,
                FirstName    = firstName.Text,
                JobTitle     = jobTitle.Text,
                LastName     = lastName.Text,
                Location     = location.Text,
                PhoneNumber  = phoneNumber.Text,
                EmployeeID   = employeeID.Text,
            };

            if (Utility.IsAnyNullOrEmpty(employeeContact))
            {
                StatusMessage.Text       = "Oops. All fields are mandatory. Could you please add all required details?";
                StatusMessage.Visibility = Visibility;
            }

            else
            {
                string textFilePath = await Utility.AddEmployeeContact(employeeContact);

                StatusMessage.Text       = "New Employee Contact Added Successfuly. Click on 'Display Phone Book' to see the record you just added.";
                StatusMessage.Visibility = Visibility;
            }

            emailAddress.Text = string.Empty;
            firstName.Text    = string.Empty;
            jobTitle.Text     = string.Empty;
            lastName.Text     = string.Empty;
            location.Text     = string.Empty;
            phoneNumber.Text  = string.Empty;
            employeeID.Text   = string.Empty;
        }
示例#2
0
        public static async Task <string> AddEmployeeContact(EmployeeContact employeeContact)
        {
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile   textFile    = await localFolder.CreateFileAsync(TEXT_FILE_NAME, CreationCollisionOption.OpenIfExists);

            var content = JsonConvert.SerializeObject(employeeContact);

            using (StreamWriter outputFile = new StreamWriter(textFile.Path, true))
            {
                await outputFile.WriteLineAsync(content);

                outputFile.Close();
            }
            return(textFile.Path);
        }