Skip to content
Permalink
Browse files

App.Properties for Adding and Updating

  • Loading branch information
saraford committed Dec 25, 2017
1 parent 2866d50 commit 073534aaf9719f31bdfdb1be10e538ba3eb42d64
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using ListViewInTabbedControl.Models;
using Xamarin.Forms;

namespace ListViewInTabbedControl.Services
{
@@ -11,17 +12,37 @@ public static List<Fabric> GetAllFabrics()

List<Fabric> fabrics = new List<Fabric>();

fabrics.Add(new Fabric("fabric1", 5));
fabrics.Add(new Fabric("fabric2", 5));
fabrics.Add(new Fabric("fabric3", 5));
if (Application.Current.Properties.Count == 0)
{
return fabrics;
}

for (int i = 0; i < Application.Current.Properties.Count; i++)
{
var fabric = Application.Current.Properties[i.ToString()] as Fabric;
fabrics.Add(fabric);
}

return fabrics;
}

public static void AddFabric(Fabric fabric) {
public async static void AddFabric(Fabric fabric) {

fabric.Id = Application.Current.Properties.Count;
Application.Current.Properties.Add(fabric.Id.ToString(), fabric);
await Application.Current.SavePropertiesAsync();
}

public static void UpdateFabric(Fabric fabric)
{
Xamarin.Forms.Application.Current.Properties.Remove(fabric.Id.ToString());

Xamarin.Forms.Application.Current.Properties.Add(fabric.Id.ToString(), fabric);
}

public static Fabric GetFabric(int id)
{
return Application.Current.Properties[id.ToString()] as Fabric;
}
}
}
@@ -1,6 +1,7 @@
using System;
using System.Windows.Input;
using ListViewInTabbedControl.Models;
using ListViewInTabbedControl.Services;
using MvvmHelpers;
using Xamarin.Forms;

@@ -36,12 +37,12 @@ private async void DoneEditing()
{
if (isNew) {

// FabricsDataService.AddFabric(this.Fabric);
FabricsDataService.AddFabric(this.Fabric);

MessagingCenter.Send<ItemDetailsViewModel, Fabric>(this, "added", this.Fabric);
} else {

// FabricsDataService.UpdateFabric(this.Fabric);
FabricsDataService.UpdateFabric(this.Fabric);

}

0 comments on commit 073534a

Please sign in to comment.
You can’t perform that action at this time.