Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • samples
  • apis
  • Order.Api
  • Repository
  • IOrderRepository.cs
Find file
BlameHistoryPermalink
  • 丁松杰's avatar
    添加可靠消息demo · 610f963f
    丁松杰 committed 5 years ago
    610f963f
IOrderRepository.cs 1.21 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ServiceA.Repository
{
    public interface IOrderRepository
    {
        Order.Api.Entity.Order Get(int id);
        bool Add(Order.Api.Entity.Order order);
        bool Save(Order.Api.Entity.Order order);
    }
    class OrderRepository : IOrderRepository
    {
        private static ConcurrentBag<Order.Api.Entity.Order> Orders = new ConcurrentBag<Order.Api.Entity.Order>();
        public OrderRepository()
        {
            Orders.Add(new Order.Api.Entity.Order { Id = 1, Price = 12 });
        }
        public Order.Api.Entity.Order Get(int id)
        {
            return Orders.FirstOrDefault(m => m.Id == id);
        }

        public bool Add(Order.Api.Entity.Order order)
        {
            Orders.Add(order);
            return true;
        }

        public bool Save(Order.Api.Entity.Order order)
        {
            var currentOrder = Orders.FirstOrDefault(m => m.Id == order.Id);
            if (currentOrder == null)
            {
                return false;
            }
            currentOrder.Price = order.Price;
            return true;
        }
    }
}