diff --git a/src/Functions/SantaTalk.Models/Letter.cs b/src/Functions/SantaTalk.Models/Letter.cs
new file mode 100644
index 0000000..56235ce
--- /dev/null
+++ b/src/Functions/SantaTalk.Models/Letter.cs
@@ -0,0 +1,10 @@
+using System;
+namespace SantaTalk.Models
+{
+ public class Letter
+ {
+ public string Sender { get; set; }
+ public string Receiver { get; set; }
+ public string Message { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Functions/SantaTalk.Models/SantaResultDisplay.cs b/src/Functions/SantaTalk.Models/SantaResultDisplay.cs
index c111996..a5337e1 100644
--- a/src/Functions/SantaTalk.Models/SantaResultDisplay.cs
+++ b/src/Functions/SantaTalk.Models/SantaResultDisplay.cs
@@ -5,8 +5,13 @@
namespace SantaTalk.Models
{
public class SantaResultDisplay
- {
+ {
public string SentimentInterpretation { get; set; }
public string GiftPrediction { get; set; }
+
+ public override string ToString()
+ {
+ return SentimentInterpretation + " " + GiftPrediction;
+ }
}
}
diff --git a/src/Functions/SantaTalk.Models/SantaTalk.Models.csproj b/src/Functions/SantaTalk.Models/SantaTalk.Models.csproj
index 9f5c4f4..4345206 100644
--- a/src/Functions/SantaTalk.Models/SantaTalk.Models.csproj
+++ b/src/Functions/SantaTalk.Models/SantaTalk.Models.csproj
@@ -4,4 +4,7 @@
netstandard2.0
+
+
+
diff --git a/src/SantaTalk.Android/SantaTalk.Android.csproj b/src/SantaTalk.Android/SantaTalk.Android.csproj
index ffcd81d..f3f4076 100644
--- a/src/SantaTalk.Android/SantaTalk.Android.csproj
+++ b/src/SantaTalk.Android/SantaTalk.Android.csproj
@@ -69,6 +69,9 @@
12.0.3
+
+ 1.6.292
+
diff --git a/src/SantaTalk.iOS/SantaTalk.iOS.csproj b/src/SantaTalk.iOS/SantaTalk.iOS.csproj
index 19ef860..46e5e8e 100644
--- a/src/SantaTalk.iOS/SantaTalk.iOS.csproj
+++ b/src/SantaTalk.iOS/SantaTalk.iOS.csproj
@@ -139,6 +139,9 @@
12.0.3
+
+ 1.6.292
+
diff --git a/src/SantaTalk/LetterHistoryPage.xaml b/src/SantaTalk/LetterHistoryPage.xaml
new file mode 100644
index 0000000..67268aa
--- /dev/null
+++ b/src/SantaTalk/LetterHistoryPage.xaml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/SantaTalk/LetterHistoryPage.xaml.cs b/src/SantaTalk/LetterHistoryPage.xaml.cs
new file mode 100644
index 0000000..625a9f5
--- /dev/null
+++ b/src/SantaTalk/LetterHistoryPage.xaml.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using SantaTalk.ViewModels;
+using Xamarin.Forms;
+
+namespace SantaTalk
+{
+ public partial class LetterHistoryPage : ContentPage
+ {
+ public LetterHistoryPage()
+ {
+ BindingContext = new LetterHistoryPageViewModel();
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/SantaTalk/MainPage.xaml b/src/SantaTalk/MainPage.xaml
index 7263026..2dab42a 100644
--- a/src/SantaTalk/MainPage.xaml
+++ b/src/SantaTalk/MainPage.xaml
@@ -39,7 +39,12 @@
-
+
+
+
+
diff --git a/src/SantaTalk/ResultsPage.xaml b/src/SantaTalk/ResultsPage.xaml
index a31892f..1f4fbb5 100644
--- a/src/SantaTalk/ResultsPage.xaml
+++ b/src/SantaTalk/ResultsPage.xaml
@@ -8,7 +8,7 @@
x:Class="SantaTalk.ResultsPage"
ios:Page.UseSafeArea="True"
BackgroundColor="{StaticResource dark_gradient}"
- NavigationPage.HasNavigationBar="False">
+ Title="Results">
diff --git a/src/SantaTalk/SantaTalk.csproj b/src/SantaTalk/SantaTalk.csproj
index 7ad5715..c39a8bd 100644
--- a/src/SantaTalk/SantaTalk.csproj
+++ b/src/SantaTalk/SantaTalk.csproj
@@ -18,6 +18,7 @@
+
diff --git a/src/SantaTalk/Services/LetterDeliveryService.cs b/src/SantaTalk/Services/LetterDeliveryService.cs
index 9a55d77..7c77fd2 100644
--- a/src/SantaTalk/Services/LetterDeliveryService.cs
+++ b/src/SantaTalk/Services/LetterDeliveryService.cs
@@ -3,12 +3,20 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using SantaTalk.Models;
+using SantaTalk.Services;
using Xamarin.Essentials;
namespace SantaTalk
{
public class LetterDeliveryService
{
+ private LettersHistoryService _lettersHistoryService;
+
+ public LetterDeliveryService()
+ {
+ _lettersHistoryService = new LettersHistoryService();
+ }
+
//string santaUrl = "{REPLACE WITH YOUR FUNCTION URL}/api/WriteSanta";
string santaUrl = "http://localhost:7071/api/WriteSanta";
@@ -30,6 +38,8 @@ public async Task WriteLetterToSanta(SantaLetter letter)
var httpResponse = await httpClient.PostAsync(santaUrl, new StringContent(letterJson));
results = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync());
+
+ _lettersHistoryService.SaveLetterAndResults(letter, results);
return results;
}
diff --git a/src/SantaTalk/Services/LettersHistoryService.cs b/src/SantaTalk/Services/LettersHistoryService.cs
new file mode 100644
index 0000000..0e13521
--- /dev/null
+++ b/src/SantaTalk/Services/LettersHistoryService.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SantaTalk.Models;
+using SQLite;
+using SQLitePCL;
+
+namespace SantaTalk.Services
+{
+ public class LettersHistoryService
+ {
+ private SQLiteConnection _db;
+ private SantasCommentsService _santaResultDisplay;
+
+ public LettersHistoryService()
+ {
+ _santaResultDisplay = new SantasCommentsService();
+
+ var databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyData.db");
+ _db = new SQLiteConnection(databasePath);
+ _db.CreateTable();
+ }
+
+ public IList ListLetters()
+ {
+ return _db.Table().ToList();
+ }
+
+ public void SaveLetterAndResults(SantaLetter letter, SantaResults results)
+ {
+ var santaResultDisplay = _santaResultDisplay.MakeGiftDecision(results);
+ var santaLetter = new Letter()
+ {
+ Message = letter.LetterText,
+ Receiver = "Santa",
+ Sender = letter.KidName
+ };
+
+ var resultsLetter = new Letter()
+ {
+ Message = santaResultDisplay.ToString(),
+ Sender = "Santa",
+ Receiver = results.KidName
+ };
+
+ _db.InsertAll(new List() { santaLetter, resultsLetter }, true);
+ }
+ }
+}
diff --git a/src/SantaTalk/ViewModels/LetterHistoryPageViewModel.cs b/src/SantaTalk/ViewModels/LetterHistoryPageViewModel.cs
new file mode 100644
index 0000000..0ca92b1
--- /dev/null
+++ b/src/SantaTalk/ViewModels/LetterHistoryPageViewModel.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using SantaTalk.Models;
+using SantaTalk.Services;
+
+namespace SantaTalk.ViewModels
+{
+ public class LetterHistoryPageViewModel
+ {
+ public IList Letters { get; set; }
+
+ public LetterHistoryPageViewModel()
+ {
+ var lettersService = new LettersHistoryService();
+ Letters = lettersService.ListLetters();
+ }
+ }
+}
diff --git a/src/SantaTalk/ViewModels/MainPageViewModel.cs b/src/SantaTalk/ViewModels/MainPageViewModel.cs
index 2663946..f435e01 100644
--- a/src/SantaTalk/ViewModels/MainPageViewModel.cs
+++ b/src/SantaTalk/ViewModels/MainPageViewModel.cs
@@ -6,13 +6,18 @@
namespace SantaTalk
{
public class MainPageViewModel : BaseViewModel
- {
+ {
public MainPageViewModel()
- {
+ {
SendLetterCommand = new Command(async () =>
{
await Application.Current.MainPage.Navigation.PushAsync(new ResultsPage(KidsName, LetterText));
});
+
+ SeeHistoryCommand = new Command(async () =>
+ {
+ await Application.Current.MainPage.Navigation.PushAsync(new LetterHistoryPage());
+ });
}
string kidsName;
@@ -30,5 +35,6 @@ public string LetterText
}
public ICommand SendLetterCommand { get; }
+ public ICommand SeeHistoryCommand { get; }
}
}