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))); }
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); }
public async Task Should_get_portfolio() { var response = await _portfolioService.GetPortfolio(CancellationToken.None); ValidateRestResponse(response); Assert.NotNull(response.Positions); }
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)); }
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))); }
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; } }
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)); }
public IActionResult Get() { try { var data = _portfolioService.GetPortfolio(); if (data == null) { return(NotFound()); } return(Ok(data)); } catch (Exception ex) { return(BadRequest(ex)); } }
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); }
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)); }
public async Task <CompletePortfolio> Handle(GetPortfolioQuery request, CancellationToken cancellationToken) { var result = await _portfolioService.GetPortfolio(); return(result); }
public IActionResult GetPortfolio() { var portfolio = _portfolioService.GetPortfolio(UserId); return(Ok(portfolio)); }