Ejemplo n.º 1
0
        public IActionResult AddHolding([FromBody] HoldingDto holdingDto)
        {
            if (holdingDto?.CoinTickerSymbol == null)
            {
                return(BadRequest("Incomplete information"));
            }

            var userPortfolio = _portfolioRepo.GetPortfolio(UserId);

            if (userPortfolio == null)
            {
                return(NotFound("Porfolio for this user was not found"));
            }

            if (userPortfolio.Holdings?.Any(h => h.CoinTickerSymbol == holdingDto.CoinTickerSymbol) ?? false)
            {
                return(BadRequest($"Portfolio already has an entry with ticker symbol {holdingDto.CoinTickerSymbol}"));
            }

            var holding = new Holding
            {
                UserId           = UserId,
                AmountOwned      = holdingDto.AmountOwned,
                CoinTickerSymbol = holdingDto.CoinTickerSymbol,
                PortfolioId      = userPortfolio.Id
            };

            holding = _holdingsRepo.CreateHolding(holding);
            return(Ok(holding));
        }
Ejemplo n.º 2
0
        public IActionResult DeleteHolding([FromBody] HoldingDto holdingDto)
        {
            var holding = new Holding
            {
                UserId           = UserId,
                CoinTickerSymbol = holdingDto.CoinTickerSymbol
            };

            _holdingsRepo.DeleteHolding(holding);
            return(Ok($"{holdingDto.CoinTickerSymbol} removed from portfolio"));
        }
Ejemplo n.º 3
0
        public IActionResult UpdateHolding([FromBody] HoldingDto holdingDto)
        {
            var holding = new Holding
            {
                CoinTickerSymbol = holdingDto.CoinTickerSymbol,
                AmountOwned      = holdingDto.AmountOwned,
                UserId           = UserId
            };

            holding = _holdingsRepo.UpdateHolding(holding);

            return(Ok(holding));
        }