コード例 #1
0
        public ActionResult CreatePortfolio(Portfolio portfolio)
        {
            portfolio.UserId = UserId;

            var addRes      = _portfolioService.CreatePortfolio(portfolio);
            var dbPortfolio = _portfolioService.GetPortfolio(p => p.UserId == UserId);

            return(Ok(new PortfolioModel(dbPortfolio)));
        }
コード例 #2
0
        public async Task <PortfolioService.SharesViewModel> CreateShare(CreateShareViewModel viewModel)
        {
            PortfolioService.PortfolioViewModel portfolio = null;

            // Check if portfolioId is correct
            if (viewModel.PortfolioId != null && viewModel.PortfolioId != Guid.Empty)
            {
                portfolio = await _portfolioService.GetPortfolio(viewModel.PortfolioId);

                if (portfolio == null)
                {
                    throw new ArgumentException("PortfolioId doesn't match any existing portfolios");
                }
            }
            else
            {
                portfolio = await _portfolioService.GetPortfolioByUser(viewModel.UserId);

                if (portfolio == null)
                {
                    portfolio = await _portfolioService.CreatePortfolio(viewModel.UserId);
                }
                viewModel.PortfolioId = portfolio.PortfolioId;
            }

            var share = await _portfolioService.CreateShare(viewModel.PortfolioId, viewModel.Name, viewModel.TotalValue, viewModel.Count);

            if (share == null)
            {
                throw new ArgumentException("Couldn't create share");
            }

            return(share);
        }
コード例 #3
0
        public async Task Should_get_portfolio()
        {
            var response = await _portfolioService.GetPortfolio(CancellationToken.None);

            ValidateRestResponse(response);
            Assert.NotNull(response.Positions);
        }
コード例 #4
0
        public async Task <ActionResult <Property> > PostProperty(Guid portfolioId, PropertyCreateDto @property)
        {
            //var address = _mapper.Map<Address>(@property.Address);
            var portfolio = await _portfolioService.GetPortfolio(portfolioId);

            var newProperty = _mapper.Map <Property>(@property);
            var result      = await _propertyService.CreateProperty(portfolio, newProperty);

            return(CreatedAtAction("GetProperty", new { id = result.Id }, result));
        }
コード例 #5
0
        public ActionResult CreatePortfolio(Portfolio portfolio)
        {
            var user = User.GetUserDetails();

            portfolio.UserId = user.UserId;

            var addRes      = _portfolioService.CreatePortfolio(portfolio);
            var dbPortfolio = _portfolioService.GetPortfolio(user.UserId);

            return(Ok(new PortfolioModel(dbPortfolio)));
        }
コード例 #6
0
        public async Task <ActionResult <PortfolioDetailsDto> > GetPortfolio(Guid id)
        {
            var portfolio = await _portfolioService.GetPortfolio(id);

            if (portfolio == null)
            {
                return(NotFound());
            }
            try
            {
                var portfolioDetails = _mapper.Map <PortfolioDetailsDto>(portfolio);
                return(Ok(portfolioDetails));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));

                throw;
            }
        }
コード例 #7
0
ファイル: NavController.cs プロジェクト: MihA-aa/Invest-site
        public ActionResult _General(int?id)
        {
            if (id == null)
            {
                return(PartialView());
            }
            var portfolioDto = portfolioService.GetPortfolio(id);
            var portfolio    = Mapper.Map <PortfolioDTO, PortfolioModel>(portfolioDto);

            TempData["PortfolioId"] = portfolioDto.Id;
            return(PartialView(portfolio));
        }
コード例 #8
0
        public IActionResult Get()
        {
            try
            {
                var data = _portfolioService.GetPortfolio();

                if (data == null)
                {
                    return(NotFound());
                }
                return(Ok(data));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
コード例 #9
0
        public ActionResult <double> CalculateNetworth(int portfolioId)
        {
            if (portfolioId < 0)
            {
                return(this.BadRequest("Incorect ID"));
            }

            PortfolioDetails portfolioDetails = _PortfolioService.GetPortfolio(portfolioId);

            if (portfolioDetails == null)
            {
                return(this.BadRequest("Empty Portfolio"));
            }

            double result = _PortfolioService.CalculateNetworth(portfolioDetails).Result;

            return(result);
        }
コード例 #10
0
        public IHttpActionResult Get(int id)
        {
            PortfolioInformationModel portfolio;

            try
            {
                if (portfolioService.CheckAccess(RequestContext.Principal.Identity.GetUserId(), id))
                {
                    portfolio = Mapper.Map <PortfolioDTO, PortfolioInformationModel>(portfolioService.GetPortfolio(id));
                }
                else
                {
                    throw new Exception("You don't have access to portfolio with id: " + id);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                return(BadRequest(ex.ToString()));
            }
            return(Ok(portfolio));
        }
コード例 #11
0
        public async Task <CompletePortfolio> Handle(GetPortfolioQuery request, CancellationToken cancellationToken)
        {
            var result = await _portfolioService.GetPortfolio();

            return(result);
        }
コード例 #12
0
        public IActionResult GetPortfolio()
        {
            var portfolio = _portfolioService.GetPortfolio(UserId);

            return(Ok(portfolio));
        }