This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
112 additions
and
358 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
namespace Example.Models | ||
{ | ||
public interface HasId | ||
{ | ||
string Id { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Example.Services | ||
{ | ||
public partial class BaseDataStore<T> : IDataStore<T> where T : Models.HasId | ||
{ | ||
protected List<T> items; | ||
|
||
public BaseDataStore() | ||
{ | ||
} | ||
|
||
public async Task<bool> AddItemAsync(T item) | ||
{ | ||
items.Add(item); | ||
return await Task.FromResult(true); | ||
} | ||
|
||
public async Task<bool> DeleteItemAsync(T item) | ||
{ | ||
var _item = items.AsQueryable().Where((T arg) => arg.Id == item.Id).FirstOrDefault(); | ||
items.Remove(_item); | ||
|
||
return await Task.FromResult(true); | ||
} | ||
|
||
public async Task<T> GetItemAsync(string id) | ||
{ | ||
return await Task.FromResult(items.FirstOrDefault(s => s.Id == id)); | ||
} | ||
|
||
public async Task<IEnumerable<T>> GetItemsAsync(bool forceRefresh = false) | ||
{ | ||
return await Task.FromResult(items); | ||
} | ||
|
||
public async Task<bool> UpdateItemAsync(T item) | ||
{ | ||
var _item = items.Where<T>((T arg) => arg.Id == item.Id).FirstOrDefault(); | ||
items.Remove(_item); | ||
items.Add(item); | ||
|
||
return await Task.FromResult(true); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using Example.Models; | ||
|
||
[assembly: Xamarin.Forms.Dependency(typeof(Example.Services.NavigationDataStore))] | ||
namespace Example.Services | ||
{ | ||
public class NavigationDataStore : BaseDataStore<NavItem> | ||
{ | ||
|
||
public NavigationDataStore() | ||
{ | ||
items = new List<NavItem>(); | ||
var mockItems = new List<NavItem> | ||
{ | ||
new NavItem { Id = Guid.NewGuid().ToString(), Text = "First item", Description="This is an item description." }, | ||
new NavItem { Id = Guid.NewGuid().ToString(), Text = "Second item", Description="This is an item description." }, | ||
new NavItem { Id = Guid.NewGuid().ToString(), Text = "Third item", Description="This is an item description." }, | ||
new NavItem { Id = Guid.NewGuid().ToString(), Text = "Fourth item", Description="This is an item description." }, | ||
new NavItem { Id = Guid.NewGuid().ToString(), Text = "Fifth item", Description="This is an item description." }, | ||
new NavItem { Id = Guid.NewGuid().ToString(), Text = "Sixth item", Description="This is an item description." }, | ||
}; | ||
|
||
mockItems.ForEach(item => items.Add(item)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters