添加项目文件。
This commit is contained in:
47
XXCpzs.MobileAppService/Models/ItemRepository.cs
Normal file
47
XXCpzs.MobileAppService/Models/ItemRepository.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace XXCpzs.Models
|
||||
{
|
||||
public class ItemRepository : IItemRepository
|
||||
{
|
||||
private static ConcurrentDictionary<string, Item> items =
|
||||
new ConcurrentDictionary<string, Item>();
|
||||
|
||||
public ItemRepository()
|
||||
{
|
||||
Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Item 1", Description = "This is an item description." });
|
||||
Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Item 2", Description = "This is an item description." });
|
||||
Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Item 3", Description = "This is an item description." });
|
||||
}
|
||||
|
||||
public IEnumerable<Item> GetAll()
|
||||
{
|
||||
return items.Values;
|
||||
}
|
||||
|
||||
public void Add(Item item)
|
||||
{
|
||||
item.Id = Guid.NewGuid().ToString();
|
||||
items[item.Id] = item;
|
||||
}
|
||||
|
||||
public Item Get(string id)
|
||||
{
|
||||
items.TryGetValue(id, out Item item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public Item Remove(string id)
|
||||
{
|
||||
items.TryRemove(id, out Item item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void Update(Item item)
|
||||
{
|
||||
items[item.Id] = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user