Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Functions/SantaTalk.Models/Letter.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
7 changes: 6 additions & 1 deletion src/Functions/SantaTalk.Models/SantaResultDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
3 changes: 3 additions & 0 deletions src/Functions/SantaTalk.Models/SantaTalk.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="sqlite-net-pcl" Version="1.6.292" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/SantaTalk.Android/SantaTalk.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="sqlite-net-pcl">
<Version>1.6.292</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down
3 changes: 3 additions & 0 deletions src/SantaTalk.iOS/SantaTalk.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="sqlite-net-pcl">
<Version>1.6.292</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions src/SantaTalk/LetterHistoryPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SantaTalk.LetterHistoryPage"
Title="History">
<ContentPage.Content>

<ListView
ItemsSource="{Binding Letters}"
VerticalOptions="FillAndExpand"
HasUnevenRows="True"
SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="8">

<StackLayout Orientation="Horizontal"
Spacing="8"
Grid.Row="0">
<Label Text="Sender:"
TextColor="{StaticResource dark_gradient}"
FontAttributes="Bold"/>
<Label Text="{Binding Sender}"
TextColor="{StaticResource dark_gradient}"/>
</StackLayout>
<StackLayout Orientation="Horizontal" Spacing="8"
Grid.Row="1">
<Label Text="Receiver:"
TextColor="{StaticResource dark_gradient}"
FontAttributes="Bold"/>
<Label Text="{Binding Receiver}"
TextColor="{StaticResource dark_gradient}" />
</StackLayout>

<StackLayout Orientation="Vertical"
Grid.Row="2">
<Label Text="Message:"
TextColor="{StaticResource dark_gradient}"
FontAttributes="Bold" />
<Label Text="{Binding Message}"
TextColor="{StaticResource dark_gradient}"/>
</StackLayout>

</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
16 changes: 16 additions & 0 deletions src/SantaTalk/LetterHistoryPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
7 changes: 6 additions & 1 deletion src/SantaTalk/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
<Editor Text="{Binding LetterText}" TextColor="White"/>
</StackLayout>
</StackLayout>
<Button VerticalOptions="EndAndExpand" Text="SEND TO SANTA" Margin="16" Command="{Binding SendLetterCommand}" />
<StackLayout Margin="16"
VerticalOptions="EndAndExpand"
Spacing="16">
<Button Text="SEND TO SANTA" Command="{Binding SendLetterCommand}" />
<Button Text="HISTORY" Command="{Binding SeeHistoryCommand}" />
</StackLayout>
</StackLayout>
</ScrollView>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/SantaTalk/ResultsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
x:Class="SantaTalk.ResultsPage"
ios:Page.UseSafeArea="True"
BackgroundColor="{StaticResource dark_gradient}"
NavigationPage.HasNavigationBar="False">
Title="Results">

<ContentPage.Resources>
<ResourceDictionary>
Expand Down
1 change: 1 addition & 0 deletions src/SantaTalk/SantaTalk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="Xamarin.Forms.PancakeView" Version="1.3.6" />
<PackageReference Include="Xamarin.Forms.StateSquid" Version="1.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="sqlite-net-pcl" Version="1.6.292" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Functions\SantaTalk.Models\SantaTalk.Models.csproj" />
Expand Down
10 changes: 10 additions & 0 deletions src/SantaTalk/Services/LetterDeliveryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -30,6 +38,8 @@ public async Task<SantaResults> WriteLetterToSanta(SantaLetter letter)
var httpResponse = await httpClient.PostAsync(santaUrl, new StringContent(letterJson));

results = JsonConvert.DeserializeObject<SantaResults>(await httpResponse.Content.ReadAsStringAsync());

_lettersHistoryService.SaveLetterAndResults(letter, results);

return results;
}
Expand Down
49 changes: 49 additions & 0 deletions src/SantaTalk/Services/LettersHistoryService.cs
Original file line number Diff line number Diff line change
@@ -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<Letter>();
}

public IList<Letter> ListLetters()
{
return _db.Table<Letter>().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<Letter>() { santaLetter, resultsLetter }, true);
}
}
}
18 changes: 18 additions & 0 deletions src/SantaTalk/ViewModels/LetterHistoryPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using SantaTalk.Models;
using SantaTalk.Services;

namespace SantaTalk.ViewModels
{
public class LetterHistoryPageViewModel
{
public IList<Letter> Letters { get; set; }

public LetterHistoryPageViewModel()
{
var lettersService = new LettersHistoryService();
Letters = lettersService.ListLetters();
}
}
}
10 changes: 8 additions & 2 deletions src/SantaTalk/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,5 +35,6 @@ public string LetterText
}

public ICommand SendLetterCommand { get; }
public ICommand SeeHistoryCommand { get; }
}
}