Wednesday, 21 August 2013

Windows 8 app, getting data on db change

Windows 8 app, getting data on db change

I´m developing a windows 8 store app in c# and xaml for a website(the
website is in .net mvc 4) .In the web site i can create, edit, and delete
products (i´m using sql server 2008 r2). In my w8 app i call a wcf service
to get the data and populate the items. I wanted to know if there is a way
to notify or update the data in the w8 app after someone create or edit a
product through the website. One of the posible solution that i thought,
was call the wcf service every time that the user click to see the list of
products but i dont think is a good practice. Here is my code:
//App.xaml.cs
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
ServiceProduct serviceData =
(ServiceProduct)App.Current.Resources["serviceProducts"];
if (serviceData != null)
{
if (serviceData.ListaIos.Count == 0)
{
try
{
await serviceData.GetListProductsAsync();
}
catch(ServiceException)
{
var messageDialog = new
Windows.UI.Popups.MessageDialog("Error");
var result = messageDialog.ShowAsync();
}
}
}
*** code ***
}
//Items page
protected override void LoadState(Object navigationParameter,
Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable collection of items to
this.DefaultViewModel["Items"]
ServiceProduct serviceData =
(ServiceProduct)App.Current.Resources["serviceProducts"];
if (serviceData != null)
{
this.DefaultViewModel["Items"] = serviceData.GetProducts;
}
}
public async Task GetListProductsAsync()
{
ProductServiceClient service = new ProductServiceClient();
Product product;
try
{
var wcfCall = await service.GetListaAsync();
foreach (var item in wcfCall.List)
{
map product
this.ListaIos.Add(product);
}
}
catch(Exception)
{
throw new NotImplementedException();
}
}

No comments:

Post a Comment