Skip to content

Instantly share code, notes, and snippets.

@scionwest
scionwest / gist:c3aba56115b0b20c9169
Created November 8, 2014 22:40
Validation Example
[ValidateNumberIsGreaterThan(
ComparisonProperty = "Account.MinimumBalance",
FailureMessage = "You can not withdraw anymore, you must maintain a minimum balance.",
ValidationMessageType = typeof(ValidationWarningMessage),
ValidateIfMemberValueIsValid = "Account.IsOpen")]
@scionwest
scionwest / FirstRunPage.xaml.cs
Created December 6, 2014 20:19
Updated FirstRunPage
public sealed partial class FirstRunPage : VisualStateAwarePage
{
public FirstRunPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//base.OnNavigatedTo(e);
@scionwest
scionwest / ParseRestHelper.cs
Created December 6, 2014 20:37
ParseRestHelper
//-----------------------------------------------------------------------
// <copyright file="ParseRestHelper.cs" company="Sully Studios">
// Copyright (c) Johnathon Sullinger. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Lifestream.Data.Repository.ParseCloud
{
using System;
using System.Collections.Generic;
using System.Linq;
@scionwest
scionwest / UserRepository.cs
Created December 6, 2014 20:37
UserRepository
public class UserRepository : IUserRepository
{
/// <summary>
/// Asks the data store to create a new user with the given data..
/// </summary>
/// <param name="data">The data that represents a user.</param>
/// <param name="password">The password.</param>
/// <returns>
/// Returns a session token that can be used to preserve a user session.
/// </returns>
@scionwest
scionwest / UserService.cs
Created December 6, 2014 20:38
UserService
public class UserService : IUserService
{
/// <summary>
/// The cached user for re-use once fetched.
/// </summary>
private static User _cachedUser;
/// <summary>
/// The filename used when saving the users session token.
/// </summary>
@scionwest
scionwest / ViewModelUsage.cs
Created December 6, 2014 20:39
ViewModel
private async Task ExecuteSignin()
{
this.IsSigningIn = true;
bool signinFailed = false;
string failureMesage = string.Empty;
try
{
User user = await this.userService.RetrieveUser(this.Username, this.Password);
this.navigationService.Navigate("Main", user);
protected async override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
try
{
// Try to restore the user.
IUserService userService = this.container.Resolve<IUserService>();
User user = await userService.RetrieveUser();
// If the user was restored, we can navigate to the main page.
NavigationService.Navigate("Main", user);
protected override void OnHardwareButtonsBackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
var page = (Page)((Frame)Windows.UI.Xaml.Window.Current.Content).Content;
if (page.GetType() == typeof(FirstRunPage))
{
var firstRunPage = (FirstRunPage)page;
if (firstRunPage.CanGoBack())
{
e.Handled = false;
}
@scionwest
scionwest / FirstRunPage.xaml.cs
Created December 6, 2014 21:12
FirstRunPage
public override bool CanGoBack()
{
return this.ViewModel.IsNewUser ? false : base.CanGoBack();
}
@scionwest
scionwest / App.xaml.cs
Created December 6, 2014 22:09
App.Xaml.cs override
protected override void OnHardwareButtonsBackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
var page = (Page)((Frame)Windows.UI.Xaml.Window.Current.Content).Content;
if (page is INavigateBackwards)
{
var firstRunPage = (INavigateBackwards)page;
if (!firstRunPage.CanNavigateBack())
{
e.Handled = true;
return;