public IActionResult PostUserInvestment([FromBody] UserInvestment investment)
        {
            var result = _repository.AddUserInvestment(investment);

            if (result != ResponseCategory.Succeeded)
            {
                return(BadRequest(result)); // In order to show proper error message in the Frontend.
            }
            return(Ok(result));
        }
        public void GetCostBasisPerShare_TypicalValues_ExpectCorrectAnswer()
        {
            // Arrange
            decimal           originalSharePrice  = 125.44M;
            int               numShares           = 44;
            InvestmentProduct investmentProduct   = new InvestmentProduct(1, "ABC", 1223.67M, DateTime.Now);
            TradeTransaction  purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, DateTime.Now, numShares, originalSharePrice);
            UserInvestment    userInvestment      = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction);

            // Act
            decimal basisCost = userInvestment.GetCostPerBasisShare();

            // Assert
            Assert.AreEqual(originalSharePrice * numShares, basisCost);
        }
        public void GetTerm_GreaterThan365_expectLong()
        {
            // Arrange
            decimal           originalSharePrice  = 125.44M;
            decimal           currentPrice        = 99.33M;
            int               numShares           = 44;
            DateTime          currentDate         = new DateTime(2020, 5, 12);
            DateTime          purchaseDate        = new DateTime(2018, 1, 15);
            InvestmentProduct investmentProduct   = new InvestmentProduct(1, "ABC", currentPrice, currentDate);
            TradeTransaction  purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, purchaseDate, numShares, originalSharePrice);
            UserInvestment    userInvestment      = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction);

            // Act
            InvestmentTerm actualTerm = userInvestment.GetTerm();

            // Assert
            Assert.AreEqual(InvestmentTerm.Long, actualTerm);
        }
        public void GetTotalGainLoss_PriceDropped_ExpectCorrectNegativeAnswer()
        {
            // Arrange
            decimal           originalSharePrice  = 125.44M;
            decimal           currentPrice        = 99.33M;
            int               numShares           = 44;
            InvestmentProduct investmentProduct   = new InvestmentProduct(1, "ABC", currentPrice, DateTime.Now);
            TradeTransaction  purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, DateTime.Now.AddMonths(-4), numShares, originalSharePrice);
            UserInvestment    userInvestment      = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction);

            // Act
            decimal loss = userInvestment.GetTotalGainLoss();

            // Assert
            decimal expectedLoss = (currentPrice - originalSharePrice) * numShares;

            Assert.AreEqual(expectedLoss, loss);
        }
        public ResponseCategory AddUserInvestment(UserInvestment userInvestment)
        {
            var minAmount = 100;   //_configuration.GetValue<decimal>("Investments:Min");
            var maxAmount = 10000; // _configuration.GetValue<decimal>("Investments:Max");

            if (userInvestment.InvestmentPaid < minAmount || userInvestment.InvestmentPaid > maxAmount)
            {
                return(ResponseCategory.InvalidInvestmentRang);// Paid Investment must be between 100 and 10,000
            }
            var alreadyExistUserFund = _dbContext.UserInvestments.FirstOrDefault(invs =>
                                                                                 invs.FundId == userInvestment.FundId && invs.UserId.Trim() == userInvestment.UserId.Trim());

            if (alreadyExistUserFund != null)
            {
                return(ResponseCategory.InvestmentAlreadyExists); // Just for POC purpose
            }
            _dbContext.UserInvestments.Add(userInvestment);
            _dbContext.SaveChanges();
            return(ResponseCategory.Succeeded); // Just for POC purpose
        }
        public void GetUserInvestments()
        {
            //Testing the get investments method
            // Arrange
            InvPerformanceController controller = new InvPerformanceController();
            string userName = "******";
            List <UserInvestment> testList    = new List <UserInvestment>();
            UserInvestment        testElement = new UserInvestment();

            testElement.userName = "******";
            testList.Add(testElement);


            // Act
            List <UserInvestment> result = controller.Get(userName);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(testList.ElementAt(0).userName, result.ElementAt(0).userName);
        }
Beispiel #7
0
        private void DisplayInvestmentDetails(UserInvestment selectedInvestment)
        {
            try
            {
                InvestmentProduct product     = selectedInvestment.GetInvestmentProduct();
                TradeTransaction  transaction = selectedInvestment.GetPurchaseTransaction();
                investmentName.InnerText    = product.Name;
                numShares.InnerText         = transaction.NumShares.ToString();;
                costBasisPerShare.InnerText = selectedInvestment.GetCostPerBasisShare().ToString("C3");
                currentValue.InnerText      = selectedInvestment.GetCurrentValue().ToString("C3");
                currentPrice.InnerText      = product.CurrentPrice.ToString("C3");
                term.InnerText          = selectedInvestment.GetTerm().ToString();
                totalGainLoss.InnerText = selectedInvestment.GetTotalGainLoss().ToString("C3");

                _nLogger.Info($"Displaying details for {product.Name}");
            }
            catch (Exception ex)
            {
                errorLabel.InnerText = "Error displaying investment details.  Please try again later";
                _nLogger.Error(ex, "Exception displaying investment details");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Triggers the display of investment details that the user selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void itemClicked(object sender, EventArgs e)
        {
            try
            {
                int investmentId = Int32.Parse(((LinkButton)sender).ID);

                UserInvestment selectedInvestment = _userInvestments.First(x => x.GetInvestmentProduct().Id == investmentId);
                if (selectedInvestment == null)
                {
                    errorLabel.InnerText = "Error retrieving company details";
                    _nLogger.Warn($"Unable to retrieve investment details for InvestmentId = {investmentId}");
                }
                else
                {
                    DisplayInvestmentDetails(selectedInvestment);
                }
            }
            catch (Exception ex)
            {
                errorLabel.InnerText = "Internal exception retrieving company details";
                _nLogger.Error(ex, $"Exception processing item click");
            }
        }
        public IEnumerable <UserInvestment> GetAllUserInvestments(int userId)
        {
            List <UserInvestment> products       = new List <UserInvestment>();
            InvestmentProduct     productAbc     = new InvestmentProduct(1, "Grogu Heavy Lifting", 1.23M, DateTime.Now);
            TradeTransaction      transactionAbc = new TradeTransaction(_nLogger, 1, TransactionType.Buy, new DateTime(2018, 4, 15), 100, 0.55M);
            UserInvestment        investmentAbc  = new UserInvestment(_nLogger, productAbc, transactionAbc);

            products.Add(investmentAbc);

            InvestmentProduct productBcd     = new InvestmentProduct(2, "Guild Enterprises", 44.78M, DateTime.Now);
            TradeTransaction  transactionBcd = new TradeTransaction(_nLogger, 1, TransactionType.Buy, new DateTime(2020, 11, 15), 1500, 71.00M);
            UserInvestment    investmentBcd  = new UserInvestment(_nLogger, productBcd, transactionBcd);

            products.Add(investmentBcd);

            InvestmentProduct productCde     = new InvestmentProduct(3, "Karga Holdings", 1434.78M, DateTime.Now);
            TradeTransaction  transactionCde = new TradeTransaction(_nLogger, 1, TransactionType.Buy, new DateTime(2019, 2, 1), 50, 1042.55M);
            UserInvestment    investmentCde  = new UserInvestment(_nLogger, productCde, transactionCde);

            products.Add(investmentCde);

            return(products);
        }