添加项目文件。

This commit is contained in:
杨皓
2020-04-03 11:55:02 +08:00
parent f8a6829e30
commit d4e7a559f2
178 changed files with 20595 additions and 0 deletions

View 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();
}
}

View 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; }
}
}

View 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;
}
}
}