public async Task <IActionResult> Put(NoteToCreateDTO noteToCreate) { try { noteToCreate.Message = _htmlEncoder.Encode(_javaScriptEncoder.Encode(noteToCreate.Message)); int userId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)); var portfolio = await _portfolioServices.GetPortfolioByIdAsync(noteToCreate.PortfolioId); if (portfolio == null) { return(StatusCode(400, "Portfolio with id " + noteToCreate.PortfolioId + " does not exist")); } if (portfolio.UserId == userId) { await _noteServices.CreateNote(noteToCreate); return(StatusCode(201)); } return(StatusCode(401)); } catch { return(StatusCode(500, "Something went wrong while attempting to create a note")); } }
public async Task <IActionResult> Put(PortfolioCommentToCreateDTO comment) { var portfolio = await _portfolioServices.GetPortfolioByIdAsync(comment.PortfolioId); if (portfolio == null) { return(StatusCode(400, "Portfolio with id " + comment.PortfolioId + " was not found.")); } comment.Message = _javaScriptEncoder.Encode(_htmlEncoder.Encode(comment.Message)); comment.UserId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)); var createdComment = await _commentServices.CreatePortfolioComment(comment); return(StatusCode(200)); }
public async Task <IActionResult> Get(int userId, int portfolioId, bool soldOnly) { try { bool isCurrentUser = true; if (userId == 0) { userId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)); } else { isCurrentUser = false; } if (portfolioId == 0) { var portfolios = await _portfolioServices.GetAllPortfolioByUserIdAsync(userId); if (soldOnly == true || isCurrentUser == false) { var soldPortfolios = new List <PortfolioDTO>(); foreach (PortfolioDTO p in portfolios) { if (p.IsForSale == true) { soldPortfolios.Add(p); } } return(StatusCode(200, soldPortfolios)); } return(StatusCode(200, portfolios)); } var portfolio = await _portfolioServices.GetPortfolioByIdAsync(portfolioId); if (portfolio.UserId == userId || portfolio.IsForSale == true) { return(StatusCode(200, portfolio)); } return(StatusCode(401)); } catch { return(StatusCode(500, "Something went wrong while attempting to get portfolios")); } }
public async Task <IActionResult> GetFromSold(int portfolioId) { int userId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)); var portfolio = await _portfolioServices.GetPortfolioByIdAsync(portfolioId); var orders = await _orderServices.GetOrders(portfolio.UserId, portfolioId, 0, null, null); if (await _ppServices.Exists(userId, portfolioId) || portfolio.UserId == userId) { return(StatusCode(200, orders)); } else { orders = orders.OrderBy(x => x.Timestamp).ToList(); orders = orders.Take(3).ToList(); return(StatusCode(200, orders)); } }