public static TradeOffer createTrade(ClientTrade trade, int senderId)
        {
            Core core = Core.Instance;

            int        newId         = (int)core.identities.trades.getNext();
            TradeOffer NewTradeOffer = new TradeOffer(newId, trade);

            NewTradeOffer.FetchUser();


            List <Lockable> elementsToLock = new List <Lockable>(2);

            elementsToLock.Add(NewTradeOffer.Sender.Owner);


            if (!LockingManager.lockAllOrSleep(elementsToLock))
            {
                return(null);
            }
            try
            {
                if (!NewTradeOffer.Check(senderId))
                {
                    return(null);
                }

                try
                {
                    Core.Instance.dataConnection.SaveTradeOffer(NewTradeOffer);
                    core.tradeOffer.TryAdd(NewTradeOffer.tradeOfferId, NewTradeOffer);
                }
                catch (Exception ex)
                {
                    SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex);
                }
            }
            catch (Exception ex)
            {
                core.writeExceptionToLog(ex);
            }
            finally
            {
                LockingManager.unlockAll(elementsToLock);
            }

            if (NewTradeOffer != null)
            {
                NewTradeOffer.TradingShip = Core.Instance.ships[NewTradeOffer.spaceObjectId];
                NewTradeOffer.TradingShip.TradeOffers.Add(NewTradeOffer);

                var offerSerialized = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(NewTradeOffer);
                Core.Instance.SendNewTrade(new { NewTradeOffer = offerSerialized });
            }

            return(NewTradeOffer);
        }
        public TradeOffer(int id, ClientTrade trade)
        {
            this._id       = id;
            this.offered   = new List <TradeOfferGood>();
            this.requested = new List <TradeOfferGood>();
            //this.userId = trade.Sender.Owner.id;

            this.spaceObjectId   = trade.SenderId;
            this.spaceObjectType = trade.SenderType;
            this.commNodeId      = 1;

            foreach (var offer in trade.Offered)
            {
                this.offered.Add(new TradeOfferGood(offer, id, true));
            }

            foreach (var request in trade.Requested)
            {
                this.requested.Add(new TradeOfferGood(request, id, false));
            }
        }