CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: C#

Windows Azure Mobile Services

431 Views   
// free azure trial
// http://www.windowsazure.com/en-us/pricing/free-trial/
 
// windows 8 SDK
// http://go.microsoft.com/fwlink/?LinkId=257545&clcid=0x409
 
// enable preview features
// https://account.windowsazure.com/PreviewFeatures
 
// management portal
// https://manage.windowsazure.com/?whr=live.com#Workspace/All/dashboard
 
[System.Runtime.Serialization.DataContract(Name = "Events")]
public sealed class Event : Base
{
    [System.Runtime.Serialization.DataMember(Name = "id")]
    public int Id { get; set; }
    [System.Runtime.Serialization.DataMember(Name = "Name")]
    public string Name { get; set; }
    [System.Runtime.Serialization.DataMember(Name = "Location")]
    public string Location { get; set; }
}
 
public static Microsoft.WindowsAzure.MobileServices.MobileServiceClient AzureClient
{
    get
    {
        // in portal, click MANAGE KEYS @ bottom of page
 
        string APPLICATION_URL = "https://dpeusw-xxxx.azure-mobile.net/";
        string APPLICATION_KEY = "vqFcsowZGZvyTJgAlfAqUecTnpAuXXXX";
        return new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(APPLICATION_URL, APPLICATION_KEY);
    }
}
 
ObservableCollection<Event> m_List = new ObservableCollection<Event>();
public ObservableCollection<Event> List { get { return m_List; } }
 
Event m_New = new Event();
public Event New { get { return m_New; } set { SetProperty(ref m_New, value); } }
 
Event m_Selected = null;
public Event Selected { get { return m_Selected; } set { SetProperty(ref m_Selected, value); } }
 
public async Task ReadAll()
{
    var _Table = AzureClient.GetTable<Event>();
    var _Query = _Table.Where(x => x.Name != null).OrderBy(x => x.Name);
    var _Result = await _Query.ToEnumerableAsync();
    this.List.Clear();
    foreach (var item in _Result)
        this.List.Add(item);
    this.List.Add(new AddNew());
}
 
private async void InsertNew()
{
    var _Table = AzureClient.GetTable<Event>();
    await _Table.InsertAsync(this.New);
    this.List.Add(this.New);
    this.New = null;
}
 
private async void UpdateSelected()
{
    var _Table = AzureClient.GetTable<Event>();
    await _Table.UpdateAsync(this.Selected);
    var _Match = this.List.Cast<Event>().First(x => x.Id == this.Selected.Id);
    var _Index = this.List.IndexOf(_Match);
    this.List.Remove(_Match);
    this.List.Insert(_Index, this.Selected);
    this.Selected = null;
}
 
private async void DeleteSelected()
{
    var _Table = AzureClient.GetTable<Event>();
    await _Table.DeleteAsync(this.Selected);
    this.List.Remove(this.Selected);
    this.Selected = null;
}
by Jerry Nixon
  November 09, 2012 @ 11:12am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies