示例#1
0
        //generates a trade for the given response and this offer, only works if both vereniging approve.
        //gets called by the vereniging that made the response - after being approved by the owner ofcourse
        public (Trade, TradeOffer) CloseTrade(int responseId, bool KeepSelling = false)
        {
            TradeResponse response = Responses.SingleOrDefault(r => r.Id == responseId);

            if (response == null)
            {
                throw new ArgumentException("This trade offer has no such trade response");
            }
            if (response.Status != TradeResponse.OfferStatusType.ApprovedByOfferOwner)
            {
                throw new ArgumentException("This response has not yet been approved by the offer owner");
            }
            TradeOffer newOffer = KeepSelling ? new TradeOffer(Owner, Amount - response.Amount) : null;

            Responses.Where(r => r != response).ToList().ForEach(r => {
                if (KeepSelling && r.Amount <= newOffer.Amount)
                {
                    newOffer.AddResponse(r.Vereniging, r.Amount);
                }
                else
                {
                    r.Status = TradeResponse.OfferStatusType.Declined;
                }
            });
            Trade trade = new Trade(response.Amount, Owner, response.Vereniging);

            return(trade, newOffer);
        }
示例#2
0
        //gets called when the owner approves a response
        public void ApproveResponse(int responseId)
        {
            if (Responses.Any(r => r.Status == TradeResponse.OfferStatusType.ApprovedByOfferOwner))
            {
                throw new ArgumentException("Een andere reactie is reeds goedgekeurd...");
            }
            TradeResponse response = Responses.SingleOrDefault(r => r.Id == responseId);

            if (response == null)
            {
                throw new ArgumentException("This trade offer has no such trade response");
            }
            response.Status = TradeResponse.OfferStatusType.ApprovedByOfferOwner;
        }