Beispiel #1
0
        public static void SellShare(ShareOnMarket share, Member user)
        {
            //Add transaction
            PortfolioShareTransation transaction = new PortfolioShareTransation();

            transaction.BuyerUsername      = user.Name;
            transaction.DateSold           = DateTime.Now;
            transaction.PortfolioProductId = share.PortfolioProductId;
            transaction.SellerUsername     = share.Username;
            transaction.SoldAmount         = share.Price;
            transaction.SoldFee            = CalculateFee(share.Price);
            transaction.Units = share.SharesToSell;
            transaction.Save();

            //Remove old share
            PortfolioShare Old = new PortfolioShare(share.PortfolioShareId);

            Old.Shares -= share.SharesToSell;
            Old.Save();

            //Add new share
            PortfolioShare New = GetProperShare(share, user);

            New.Shares += share.SharesToSell;
            New.Save();

            //Remove from market
            share.Delete();

            //Earnings stats
            EarningsStatsManager.Add(EarningsStatsType.PortfolioUnits, transaction.SoldFee);
        }