Esempio n. 1
0
        /// <summary>
        /// Buys the stock.
        /// </summary>
        /// <param name="selectedUser">The selected user.</param>
        public async Task BuyStock(object selectedUser, DateTime dateTime)
        {
            IsValidationMessageVisible = false;
            this.IsBusy = true;

            var basePrice     = Quantity * Price;
            var commission    = CalculateCommission(basePrice);
            var newPrice      = basePrice + commission;
            var transactionId = Guid.NewGuid();
            var portfolio     = new PostPortfolio()
            {
                TransactionId   = transactionId,
                Date            = dateTime.ToString(),
                Price           = Price,
                Company         = ShareName.ToUpper(),
                Quantity        = Quantity,
                Name            = selectedUser.ToString(),
                TransactionType = Constants.Buy,
                Total           = newPrice
            };
            await tmsService.PostPortfolioData(portfolio);

            await UpdateStockDB();
            await CalculateBuyAverage(selectedUser, newPrice, transactionId);

            ResetValue();
            this.IsBusy = false;
        }
Esempio n. 2
0
        /// <summary>
        /// Sells the stock.
        /// </summary>
        /// <param name="selectedUser">The selected user.</param>
        public async Task SellStock(object selectedUser, DateTime dateTime)
        {
            IsValidationMessageVisible = false;
            this.IsBusy = true;
            var basePrice     = Quantity * Price;
            var commission    = CalculateCommission(basePrice);
            var newPrice      = basePrice - commission;
            var transactionId = Guid.NewGuid();
            var portfolio     = new PostPortfolio()
            {
                TransactionId   = transactionId,
                Date            = dateTime.ToString(),
                Price           = Price,
                Company         = ShareName.ToUpper(),
                Quantity        = Quantity,
                Name            = selectedUser.ToString(),
                TransactionType = Constants.Sell,
                Total           = newPrice
            };

            await CalculateSellAverage(selectedUser, newPrice, transactionId);

            if (!IsBalanceNegative)
            {
                await tmsService.PostPortfolioData(portfolio);
                await UpdateStockDB();

                ResetValue();
            }
            else
            {
                this.IsBusy = false;
                UserDialogs.Instance.Alert("Selling quantity is more than available quantity.", okText: "OK");
            }
            this.IsBusy = false;
        }
Esempio n. 3
0
 /// <summary>
 /// Posts the portfolio data.
 /// </summary>
 /// <param name="portfolio">The portfolio.</param>
 public async Task PostPortfolioData(PostPortfolio portfolio)
 {
     await firebase
     .Child(Constants.TableNamePortfolio).Child(portfolio.TransactionId.ToString())
     .PutAsync(portfolio);
 }