添加项目文件。
This commit is contained in:
14
XXCpzs.MobileAppService/Models/IItemRepository.cs
Normal file
14
XXCpzs.MobileAppService/Models/IItemRepository.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XXCpzs.Models
|
||||
{
|
||||
public interface IItemRepository
|
||||
{
|
||||
void Add(Item item);
|
||||
void Update(Item item);
|
||||
Item Remove(string key);
|
||||
Item Get(string id);
|
||||
IEnumerable<Item> GetAll();
|
||||
}
|
||||
}
|
||||
16
XXCpzs.MobileAppService/Models/Item.cs
Normal file
16
XXCpzs.MobileAppService/Models/Item.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace XXCpzs.Models
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Text { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
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