public void CanUpdatePortfolio() { portfolioRepository.Setup(c => c.IsExist(It.IsAny <int>())) .Returns((int i) => ListPortfolios.Any(c => c.Id == i)); portfolioRepository.Setup(m => m.Update(It.IsAny <Portfolio>())) .Callback <Portfolio>(p => { int index = ListPortfolios.IndexOf(ListPortfolios.FirstOrDefault(c => c.Id == p.Id)); ListPortfolios[index] = p; }); UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object); portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object); #region PortfolioDTO updatePortfolio = new PortfolioDTO { Id = 1, Name = "Update Portfolio", Notes = "A portfolio is a grouping of financial assets such as stocks,", DisplayIndex = 1, LastUpdateDate = new DateTime(2017, 4, 28), Visibility = false, Quantity = 2, PercentWins = 73.23m, BiggestWinner = 234.32m, BiggestLoser = 12.65m, AvgGain = 186.65m, MonthAvgGain = 99.436m, PortfolioValue = 1532.42m }; #endregion portfolioService.UpdatePortfolio(updatePortfolio); Assert.IsTrue(ListPortfolios.FirstOrDefault(c => c.Id == 1).Name == "Update Portfolio"); }
private void GetTradePortfolio() { PortfolioDTO dto = trackerBusinessLogic.GetTradePortfolio(); Trades = dto.Trades; TradesPNL = dto.TradesPNL; }
public IActionResult putPortfolio(int id, PortfolioDTO por) { Portfolio p = _pRepository.GetBy(id); if (p == null) { return(NotFound()); } if (por.Name != "") { p.Name = por.Name; } if (por.Description != "") { p.Description = por.Description; } //if (por.UserImage != null) { p.UserImage = por.UserImage; } //if (por.Resume != null) { p.Resume = por.Resume; } _pRepository.Update(p); _pRepository.SaveChanges(); return(NoContent()); }
public List <PortfolioDTO> GetGameTransactions(int gameId) { var players = gameEntities.Players.Where(x => x.GameId == gameId && x.IsActive == true).ToList(); var list = gameEntities.ViewPlayerPortfolios.Where(a => a.GameId == gameId).ToList(); var returnList = new List <PortfolioDTO>(); foreach (var player in players) { var temp = new PortfolioDTO(); temp.PlayerId = player.PlayerId; temp.PlayerName = player.PlayerName; temp.Balance = player.BankAccounts.FirstOrDefault() != null?player.BankAccounts.FirstOrDefault().Balance : 0; temp.Transactions = list.Where(a => a.PlayerId == player.PlayerId).Select(g => new PlayerPortfolioDTO() { StockName = g.StockName, Quantity = g.Quantity, PlayerId = g.PlayerId, StockId = g.StockId, GameId = g.GameId, UnitPrice = g.UnitPrice, IsWithdraw = g.IsWithdraw, IsDeposit = g.IsDeposit, Amount = g.Amount, SectorId = g.SectorId, SectorName = g.SectorName }).ToList(); returnList.Add(temp); } return(returnList); }
public void DeletePortfolio(PortfolioDTO portfolioDTO) { var portfolio = AutoMapper.Mapper.Map <Portfolio>(portfolioDTO); _portfolioRepository.Delete(portfolio); _unitOfWork.Commit(); }
public PortfolioDTO GetTradePortfolio() { PortfolioDTO dto = new PortfolioDTO(); dto.Trades = databaseService.GetTrades(); dto.TradesPNL = CalculateTradesPNL(dto.Trades); return(dto); }
public async Task <PortfolioDTO> UpdatePortfolioData(PortfolioDTO data) { var user = _mapper.Map <User>(data); var userDataDTO = await _portfolioRepository.UpdatePortfolio(user); return(_mapper.Map <PortfolioDTO>(userDataDTO)); }
public void CreatePortFolio(PortfolioDTO portfolio) { if (!String.IsNullOrEmpty(portfolio.Title) && portfolio.PageCategory != null && !String.IsNullOrEmpty(portfolio.Content) && portfolio.CreationDate != null && portfolio.Comments != null) { portfolioAccess.Create(portfolio); return; } throw new Exception("One or more portfolio items are empty or null"); }
public PortfolioDTO Get(PortfolioDTO obj) { foreach (PortfolioDTO port in test.Portfolios) { if (port.Title == obj.Title && port.CreationDate == obj.CreationDate && port.Content == obj.Content) { return(port); } } return(null); }
public void DeletePortFolioSuccessTest() { Admin = new AdminInteractions(portfolioAccess); int index = 0; Admin.DeletePortFolio(index); PortfolioDTO result = Admin.GetPortfolio(index);//should return filenotfoundexception Assert.Fail(); }
public void PostCommentSuccessTest() { PortfolioAccess = new TPortfolioAccess(); Interactions = new UserInteractions(PortfolioAccess); AccountDTO account = new AccountDTO(0, "*****@*****.**", "Jim", "Test123"); PortfolioDTO portfolio = new PortfolioDTO(0, "Test", new List <string>(), "This is pretty short for a portfolio.", new DateTime(2020, 01, 01), new List <string>()); string comment = "This is a test comment."; Interactions.PostComment(account, portfolio, comment); Assert.AreEqual(PortfolioAccess.Read(0).Comments[0], ("Jim posted: " + comment)); }
public void PostCommentNoNicknameTest() { PortfolioAccess = new TPortfolioAccess(); Interactions = new UserInteractions(PortfolioAccess); AccountDTO account = new AccountDTO(0, "*****@*****.**", null, "Test123"); PortfolioDTO portfolio = new PortfolioDTO(0, "Test", new List <string>(), "This is pretty short for a portfolio.", DateTime.MinValue, new List <string>()); string comment = "This is a test comment."; Interactions.PostComment(account, portfolio, comment); Assert.Fail(); }
public async Task <PortfolioDTO> UpdatePortfolioAsync(PortfolioDTO portfolioToUpdate) { var portfolio = await _portfolioRepo.GetPortfolioByIdAsync(portfolioToUpdate.PortfolioId); portfolio.Name = portfolioToUpdate.Name; portfolio.Description = portfolioToUpdate.Description; portfolio.Goal = portfolioToUpdate.Goal; portfolio.IsForSale = portfolioToUpdate.IsForSale; portfolio.ImgURL = portfolioToUpdate.ImgURL; portfolio.Address = portfolioToUpdate.Address; return(ConvertPortfolio(await _genericRepo.UpdateAsync(portfolio))); }
public void CanGetPortfolioById() { portfolioRepository.Setup(c => c.Get(It.IsAny <int>())) .Returns((int i) => ListPortfolios.FirstOrDefault(c => c.Id == i)); UnitOfWork.Setup(m => m.Portfolios).Returns(portfolioRepository.Object); portfolioService = new PortfolioService(UnitOfWork.Object, validateService, customerService.Object, map, positionService.Object); PortfolioDTO portfolio1 = portfolioService.GetPortfolio(1); PortfolioDTO portfolio2 = portfolioService.GetPortfolio(2); Assert.AreEqual(portfolio1.Name, "Strategic Investment Open Portfolio"); Assert.AreEqual(portfolio2.Name, "Strategic Investment Income Portfolio"); }
public async Task CreatePortfolio(PortfolioDTO model) { try { var newportfolio = _mapper.Map <Portfolio>(model); _uow.Portfolios.Add(newportfolio); await _uow.SaveChangesAsync(); } catch (Exception ex) { throw; } }
internal TestData() { Users = new List <AccountDTO>(); GuestBookEntries = new List <GuestBookDTO>(); Portfolios = new List <PortfolioDTO>(); Users.Add(new AccountDTO(0, "*****@*****.**", "Jim", "D9B5F58F0B38198293971865A14074F59EBA3E82595BECBE86AE51F1D9F1F65E"));//Test123 GuestBookEntries.Add(new GuestBookDTO(0, DateTime.MinValue, "This is good.", "Jim")); PortfolioDTO PORTFOLIO1 = new PortfolioDTO(0, "Test", new List <string>(), "This is pretty short for a portfolio.", new DateTime(2020, 01, 01), new List <string>()); PORTFOLIO1.Comments.Add("Jimmy John Jr"); PORTFOLIO1.PageCategory.Add("Test"); Portfolios.Add(PORTFOLIO1); }
public async Task UpdatePortfolio(int portfolioId, PortfolioDTO model) { try { var portfolio = _mapper.Map <Portfolio>(model); portfolio.PortfolioId = portfolioId; _uow.Portfolios.Update(portfolio); await _uow.SaveChangesAsync(); } catch (Exception ex) { throw; } }
public void PostComment(AccountDTO User, PortfolioDTO portfolio, string Comment) { PortfolioDTO original = portfolioAccess.Get(portfolio); if (!String.IsNullOrEmpty(User.NickName)) { if (original != null) { portfolio.Comments.Add($"{User.NickName} posted: {Comment}"); portfolioAccess.Update(original, portfolio); return; } } throw new Exception("No nickname found"); }
public ActionResult <PortfolioDTO> PostPortfolio(Portfolio p) { string email = Request.HttpContext.User.Identity.Name; User u = _uRepository.GetBy(email); // Console.WriteLine(email); u.Portfolio = p; _pRepository.Add(p); _pRepository.SaveChanges(); PortfolioDTO pdto = new PortfolioDTO { Name = p.Name, Description = p.Description /*PicturePath = p.PicturePath, ResumePath = p.ResumePath*/ }; return(CreatedAtAction(nameof(GetPortfolio), new { id = p.Id }, pdto)); }
public void CreatePortFolioSuccessTest() { Admin = new AdminInteractions(portfolioAccess); PortfolioDTO portfolio = new PortfolioDTO(1, "TestTitle", new List <string>(), "Lorem Ipsum", DateTime.MinValue, new List <string>()); Admin.CreatePortFolio(portfolio); PortfolioDTO latest = portfolioAccess.GetLatestEntry(); Assert.AreEqual(portfolio.Id, latest.Id); Assert.AreEqual(portfolio.Title, latest.Title); Assert.AreEqual(portfolio.PageCategory, latest.PageCategory); Assert.AreEqual(portfolio.Content, latest.Content); Assert.AreEqual(portfolio.CreationDate, latest.CreationDate); Assert.AreEqual(portfolio.Comments, latest.Comments); Assert.AreEqual(portfolio.CreationDate, latest.EditDate); }
public int CreateOrUpdatePortfolio(PortfolioDTO portfolioDto, string userId) { if (portfolioDto == null) { throw new ValidationException(Resource.Resource.PortfolioNullReference, ""); } if (db.Portfolios.IsExist(portfolioDto.Id)) { UpdatePortfolioNameAndNotes(portfolioDto); return(portfolioDto.Id); } else { var portfolioId = CreatePortfolio(portfolioDto, userId); return(portfolioId); } }
private PortfolioDTO ConvertPortfolio(Portfolio portfolio) { var portfolioDTO = new PortfolioDTO { PortfolioId = portfolio.PortfolioId, UserId = portfolio.UserId, Name = portfolio.Name, Description = portfolio.Description, Goal = portfolio.Goal, IsForSale = portfolio.IsForSale, ImgURL = portfolio.ImgURL, Address = portfolio.Address, IsDefault = portfolio.IsDefault }; return(portfolioDTO); }
public void EditPortfolio(int index, PortfolioDTO Changes) { PortfolioDTO original = portfolioAccess.Read(index); PortfolioDTO Update = new PortfolioDTO ( original.Id, //portfolio Id String.IsNullOrEmpty(Changes.Title) ? original.Title : Changes.Title, //portfolio Title Changes.PageCategory == null ? original.PageCategory : Changes.PageCategory, //portfolio PageCategory list String.IsNullOrEmpty(Changes.Content) ? original.Content : Changes.Content, //portfolio Content original.CreationDate, Changes.Comments == null ? original.Comments : Changes.Comments, Changes.EditDate == original.EditDate ? original.EditDate : DateTime.Today ); //add current date to Changes in the edit section portfolioAccess.Update(portfolioAccess.Get(original), Update); }
public ActionResult <PortfolioDTO> GetPortfolioByUser() { string email = Request.HttpContext.User.Identity.Name; User u = _uRepository.GetBy(email); Portfolio p = u.Portfolio; if (p == null) { return(NoContent()); } PortfolioDTO pdto = new PortfolioDTO { Id = p.Id, Name = p.Name, Description = p.Description, UserImage = p.UserImage, Resume = p.Resume /*PicturePath = p.PicturePath, ResumePath = p.ResumePath*/ }; return(pdto); }
public void UpdatePortfolio(PortfolioDTO portfolioDto) { if (portfolioDto == null) { throw new ValidationException(Resource.Resource.PortfolioNullReference, ""); } if (!db.Portfolios.IsExist(portfolioDto.Id)) { throw new ValidationException(Resource.Resource.PortfolioNotFound, ""); } Mapper.Initialize(cfg => cfg.CreateMap <PortfolioDTO, Portfolio>() .ForMember("LastUpdateDate", opt => opt.MapFrom(src => DateTime.Now))); var portfolio = Mapper.Map <PortfolioDTO, Portfolio>(portfolioDto); db.Portfolios.Update(portfolio); }
public void EditPortfolioSuccessTest() { Admin = new AdminInteractions(portfolioAccess); PortfolioDTO Changes = new PortfolioDTO(0, "TestTitle", null, "Lorem Ipsum", DateTime.MinValue, null); PortfolioDTO Expected = new PortfolioDTO(0, "TestTitle", new List <string>(), "Lorem Ipsum", new DateTime(2020, 01, 01), new List <string>(), DateTime.Today); Expected.Comments.Add("Jimmy John Jr"); Expected.PageCategory.Add("Test"); Admin.EditPortfolio(Changes.Id, Changes); PortfolioDTO Result = portfolioAccess.Read(0); Assert.AreEqual(Expected.Id, Result.Id); Assert.AreEqual(Expected.Title, Result.Title); Assert.AreEqual(Expected.PageCategory.Count, Result.PageCategory.Count); //idk Assert.AreEqual(Expected.Content, Result.Content); Assert.AreEqual(Expected.CreationDate, Result.CreationDate); //wrong variable Assert.AreEqual(Expected.Comments.Count, Result.Comments.Count); //idk Assert.AreEqual(Expected.EditDate, Result.EditDate); }
public int CreatePortfolio(PortfolioDTO portfolioDto, string userId) { if (portfolioDto == null) { throw new ValidationException(Resource.Resource.PortfolioNullReference, ""); } Mapper.Initialize(cfg => cfg.CreateMap <PortfolioDTO, Portfolio>() .ForMember("LastUpdateDate", opt => opt.MapFrom(src => DateTime.Now)) .ForMember("DisplayIndex", opt => opt.MapFrom(src => db.Portfolios.Count() + 1))); var portfolio = Mapper.Map <PortfolioDTO, Portfolio>(portfolioDto); var customer = customerService.GetCustomerByProfileId(userId); portfolio.Customer = customer; customer.Portfolios.Add(portfolio); db.Portfolios.Create(portfolio); return(portfolio.Id); }
public async Task <IActionResult> Post(PortfolioDTO portfolioToUpdate) { try { if (portfolioToUpdate.Description != null) { portfolioToUpdate.Description = _htmlEncoder.Encode(_javaScriptEncoder.Encode(portfolioToUpdate.Description)); } if (portfolioToUpdate.Goal != null) { portfolioToUpdate.Goal = _htmlEncoder.Encode(_javaScriptEncoder.Encode(portfolioToUpdate.Goal)); } if (portfolioToUpdate.ImgURL != null) { portfolioToUpdate.ImgURL = _javaScriptEncoder.Encode(portfolioToUpdate.ImgURL); } if (portfolioToUpdate.Name != null) { portfolioToUpdate.Name = _htmlEncoder.Encode(_javaScriptEncoder.Encode(portfolioToUpdate.Name)); } int userId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)); var portfolio = await _portfolioServices.GetPortfolioByIdAsync(portfolioToUpdate.PortfolioId); if (portfolio == null) { return(StatusCode(400, "Portfolio with id " + portfolioToUpdate.PortfolioId + " was not found.")); } if (portfolio.UserId == userId) { await _portfolioServices.UpdatePortfolioAsync(portfolioToUpdate); return(StatusCode(200)); } return(StatusCode(401)); } catch { return(StatusCode(500, "Something went wrong while attempting to update portfolio with id " + portfolioToUpdate.PortfolioId)); } }
public async Task <IActionResult> UpdatePortfolio([FromRoute] int portfolioId, [FromBody] PortfolioDTO model) { await _itemService.UpdatePortfolio(portfolioId, model); return(Ok()); }
public async Task <IActionResult> CreatePortfolio([FromBody] PortfolioDTO model) { await _itemService.CreatePortfolio(model); return(Ok()); }