Ejemplo n.º 1
0
        public Guid Create(ThoughtRecord thoughtRecord)
        {
            string json = JsonConvert.SerializeObject(thoughtRecord, Formatting.Indented);

            SaveJsonData(json, thoughtRecord.EventGuid.ToString());

            return thoughtRecord.EventGuid;
        }
Ejemplo n.º 2
0
        public ThoughtRecord GetById(Guid guid)
        {
            ThoughtRecord thoughtRecord = new ThoughtRecord();

            // This seems weird to me, but I don't know how else to do it.
            GetThoughtRecord(thoughtRecord, guid.ToString());

            return thoughtRecord;
        }
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.
 /// This parameter is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     _thoughtRecord = (ThoughtRecord) e.Parameter;
     newThoughtRecordPageDataBinding.DataContext = _thoughtRecord;
     if (_thoughtRecord != null)
     {
         datePicker.Date = _thoughtRecord.DateTimeValue;
         timePicker.Time = _thoughtRecord.DateTimeValue.TimeOfDay;
     }
 }
Ejemplo n.º 4
0
        private async void GetThoughtRecord(ThoughtRecord thoughtRecord, string filename)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFolder targetFolder = await folder.CreateFolderAsync(thoughtRecordFolderName, CreationCollisionOption.OpenIfExists);

            StorageFile file = await targetFolder.GetFileAsync(filename);
            string json = await FileIO.ReadTextAsync(file);
            ThoughtRecord newRecord = JsonConvert.DeserializeObject<ThoughtRecord>(json);

            thoughtRecord.DateTimeValue = newRecord.DateTimeValue;
            thoughtRecord.Situation = newRecord.Situation;
            thoughtRecord.Feelings = newRecord.Feelings;
            thoughtRecord.Thoughts = newRecord.Thoughts;
            thoughtRecord.UnderlyingThoughts = newRecord.UnderlyingThoughts;
            thoughtRecord.ReplacementThoughts = newRecord.ReplacementThoughts;
        }
        private void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            DateTime dateOfEvent = new DateTime(datePicker.Date.Year, datePicker.Date.Month, datePicker.Date.Day, timePicker.Time.Hours, timePicker.Time.Minutes, timePicker.Time.Seconds);
            if (_thoughtRecord == null)
            {
                _thoughtRecord = CreateNewEventFromInputs(dateOfEvent, situationTextBox, feelingsTextBox,
                    thoughtsTextBox, underlyingThoughtsTextBox, replacementThoughtsTextBox);
            }
            else
            {
                UpdateThoughtRecord(dateOfEvent, situationTextBox, feelingsTextBox,
                    thoughtsTextBox, underlyingThoughtsTextBox, replacementThoughtsTextBox);
            }

            if (CreateNewThoughtRecord != null)
            {
                CreateNewThoughtRecord(this, _thoughtRecord);
            }
        }
        private ThoughtRecord CreateNewEventFromInputs(DateTime date, TextBox situation, TextBox feelings, TextBox thoughts, TextBox underlyingThoughts, TextBox replacementThoughts)
        {
            ThoughtRecord newThoughtRecord = new ThoughtRecord()
            {
                DateTimeValue = date,
                EventGuid = Guid.NewGuid(),
                Situation = situation.Text,
                Feelings = feelings.Text,
                Thoughts = thoughts.Text,
                UnderlyingThoughts = underlyingThoughts.Text,
                ReplacementThoughts = replacementThoughts.Text
            };

            return newThoughtRecord;
        }