//Function to add selected portfolio to list for view public static void AddToPortfolioList(string SymbolToAdd) { if (SymbolToAdd != null && PortfolioList.Where(x => x.Symbol == SymbolToAdd).Count() <= 0) { int Shares = 0; double LastPrice = 0, LastPrice2 = 0, Change = 0, Price = 0, Cost = 0, Value = 0; double Gain = 0; CompanyCounter = PortfolioList.Count() > 0 ? PortfolioList.Max(x => x.Counter) + 1 : 0; List <SymbolPriceHistory> PriceHistory = new List <SymbolPriceHistory>(); Price = 1000; GetPrices(SymbolToAdd, Price, out LastPrice, out LastPrice2, out PriceHistory); if (LastPrice2 > 0) { Change = (LastPrice - LastPrice2) / LastPrice2; } Shares = 10; Cost = Price * Shares; Value = LastPrice * Shares; if (Price > 0) { Gain = (LastPrice - Price) / Price; } PortfolioList.Add(new Portfolio(CompanyCounter, Company_Palette[CompanyCounter % Company_Palette.Length], SymbolList.Where(x => x.symbol == SymbolToAdd).Select(x => x.name).FirstOrDefault(), SymbolToAdd, true, LastPrice, Change, Shares, Price, Cost, Value, Gain, PriceHistory)); } }
public void Update() { ProjectList projects = new ProjectList(); projects.Load(); Project project = projects.FirstOrDefault(p => p.Name == "ProveIT"); PortfolioList portfolios = new PortfolioList(); portfolios.Load(); Portfolio portfolio = portfolios.FirstOrDefault(p => p.Name == "Brodys First Portfolio"); Portfolio portfolioUpdate = portfolios.FirstOrDefault(p => p.Name == "Joes First Portfolio"); PortfolioProjectList portfolioProjects = new PortfolioProjectList(); portfolioProjects.Load(); PortfolioProject portfolioProject = new PortfolioProject(); portfolioProject.LoadById(portfolioProjects.FirstOrDefault(p => p.ProjectId == project.Id && p.PortfolioId == portfolio.Id).Id); portfolioProject.PortfolioId = portfolioUpdate.Id; int rowsAffected = portfolioProject.Update(); Assert.IsTrue(rowsAffected == 1); }
public void Load() { PortfolioList portfolios = new PortfolioList(); portfolios.Load(); Assert.IsTrue(portfolios.Count > 0); }
public void LoadById() { PortfolioList portfolios = new PortfolioList(); portfolios.Load(); Portfolio portfolio = new Portfolio(); portfolio.LoadById(portfolios.FirstOrDefault(p => p.Description == "Test").Id); Assert.AreEqual("Test", portfolio.Name); }
// GET: Portfolio public ActionResult Index() { User userin = System.Web.HttpContext.Current.Session["user"] as User; if (userin == null || userin.UserTypeDescription != "Admin") { return(RedirectToAction("Index", "Home")); } portfolios = new PortfolioList(); portfolios.Load(); return(View(portfolios)); }
public void Delete() { PortfolioList portfolios = new PortfolioList(); portfolios.Load(); Portfolio portfolio = new Portfolio(); portfolio.LoadById(portfolios.FirstOrDefault(p => p.Description == "Test").Id); int rowsAffected = portfolio.Delete(); Assert.IsTrue(rowsAffected == 1); }
// ----------------------------------- START PORTFOLIO ------------------------------------------ // GET: PublicPortfolio public ActionResult PublicPortfolio(string username, string portfolioName) { User user = new User(); UserProfile up = new UserProfile() { Portfolio = new Portfolio(), Portfolios = new PortfolioList(), Projects = new ProjectList(), Privacies = new PrivacyList(), User = new User() }; UserList users = new UserList(); users.Load(); up.User = users.FirstOrDefault(p => p.UrlFriendlyName == username.ToLower()); Guid userId = user.CheckIfUsernameExists(up.User.Username); if (userId != Guid.Empty) { PortfolioList pl = new PortfolioList(); pl.LoadbyUserID(userId); up.Portfolio = pl.FirstOrDefault(p => p.UrlFriendlyName == portfolioName.ToLower()); if (up.Portfolio != null && up.Portfolio.Id != Guid.Empty) { up.User.LoadById(userId); up.Projects.LoadbyPortfolioID(up.Portfolio.Id); } else { // Portfolio doesnt exit (cleaned portfolio name passed // TO DO: ADD LOGIC FOR THIS? } } else { // Username passed doesnt exist (cleaned username passed) // TO DO: ADD LOGIC FOR THIS? } return(View(up)); }
/// <summary> /// Initializes a new instance of the <see cref="EntityRegistry"/>. /// </summary> /// <param name="storage">The special interface for direct access to the storage.</param> public EntityRegistry(IStorage storage) { if (storage == null) throw new ArgumentNullException(nameof(storage)); Storage = storage; ConfigManager.TryRegisterService(storage); Exchanges = new ExchangeList(storage) { BulkLoad = true }; ExchangeBoards = new ExchangeBoardList(storage) { BulkLoad = true }; Securities = new SecurityList(this); Trades = new TradeList(storage); MyTrades = new MyTradeList(storage); Orders = new OrderList(storage); OrderFails = new OrderFailList(storage); Portfolios = new PortfolioList(storage); Positions = new PositionList(storage); News = new NewsList(storage); }
public void LoadById() { ProjectList projects = new ProjectList(); projects.Load(); Project project = projects.FirstOrDefault(p => p.Name == "ProveIT"); PortfolioList portfolios = new PortfolioList(); portfolios.Load(); Portfolio portfolio = portfolios.FirstOrDefault(p => p.Name == "Brodys First Portfolio"); PortfolioProjectList portfolioProjects = new PortfolioProjectList(); portfolioProjects.Load(); PortfolioProject portfolioProject = new PortfolioProject(); portfolioProject.LoadById(portfolioProjects.FirstOrDefault(p => p.ProjectId == project.Id && p.PortfolioId == portfolio.Id).Id); Assert.AreEqual(portfolioProject.PortfolioId, portfolioProject.PortfolioId); }
public void Insert() { ProjectList projects = new ProjectList(); projects.Load(); Project project = projects.FirstOrDefault(p => p.Name == "TestName3"); PortfolioList portfolios = new PortfolioList(); portfolios.Load(); Portfolio portfolio = portfolios.FirstOrDefault(p => p.Name == "testprofile"); PortfolioProject portfolioProject = new PortfolioProject() { ProjectId = project.Id, PortfolioId = portfolio.Id }; int rowsInserted = portfolioProject.Insert(); Assert.IsTrue(rowsInserted == 1); }
internal void OnTradingInfo(TradingInfoResponse message) { var brokers = message.Brokers.Select(b => new AvailableBrokerInfo(b.BrokerName, b.DataFeedName,b.Accounts, b.Url, (Data.Contracts.BrokerType)b.BrokerType)).ToList(); BrokerList?.Invoke(this, new EventArgs<List<AvailableBrokerInfo>>(brokers)); PortfolioList?.Invoke(this, new EventArgs<List<TradingService.Portfolio>>(message.Portfolios)); }
public ActionResult Create(PortfolioUsers pu) { //double check authentication if (Authenticate.IsAuthenticated()) { try { pu.Privacies = new PrivacyList(); pu.Privacies.Load(); PortfolioList portfolios = new PortfolioList(); User userin = System.Web.HttpContext.Current.Session["user"] as User; string username = userin.Username; pu.Portfolio.UserId = userin.Id; pu.Portfolio.UserEmail = userin.Email; portfolios.LoadbyUser(userin); if (pu.Portfolio.Name == null) { ModelState.AddModelError(string.Empty, "Portfolio requires a name!"); } else { foreach (Portfolio p in portfolios) { if (pu.Portfolio.Name == p.Name) { ModelState.AddModelError(string.Empty, "Portfolio name already exists!"); } } } UploadedImage ui = new UploadedImage { FilePath = pu.Portfolio.PortfolioImage, Fileupload = pu.Fileupload, UserName = username, ObjectType = "Portfolio", ObjectName = pu.Portfolio.Name }; string fp = ui.Upload(); // fp will return null if no upload file was choosen else use upload file to save to database if (fp != null) { pu.Portfolio.PortfolioImage = fp; } else { // I honestly don't know when this would happen but just in case ModelState.AddModelError(string.Empty, "Portfolio Image could not found"); } if (!ModelState.IsValid) { pu.Portfolio = new Portfolio(); pu.User = new User(); pu.Privacies = new PrivacyList(); pu.Privacies.Load(); pu.User.LoadById(userin.Id); return View(pu); } pu.Portfolio.Insert(); return RedirectToAction("EditPortfolios", "UserProfile", new { returnurl = HttpContext.Request.Url }); } catch { return View(pu); } } else { return RedirectToAction("Index", "Login", new { returnurl = HttpContext.Request.Url }); } }
// GET: Portfolio public ActionResult Index() { Portfolios = new PortfolioList(); Portfolios.Load(); return View(Portfolios); }
public ActionResult EditPortfolio(Guid id, UserProfile up) { if (Authenticate.IsAuthenticated()) { try { User userin = System.Web.HttpContext.Current.Session["user"] as User; PortfolioList Portfolios = new PortfolioList(); Portfolios.LoadbyUser(userin); up.Portfolios = Portfolios; ProjectList projects = new ProjectList(); projects.LoadbyPortfolioID(id); PrivacyList privacies = new PrivacyList(); privacies.Load(); up.Privacies = privacies; up.Projects = projects; string username = userin.Username; if (up.Portfolio.Name == null) { ModelState.AddModelError(string.Empty, "Portfolio requires a name!"); } else { foreach (Portfolio p in Portfolios) { if (up.Portfolio.Name == p.Name) { if (up.Portfolio.Id != p.Id) { ModelState.AddModelError(string.Empty, "Another portfolio already exists with this name!"); } } } } UploadedImage ui = new UploadedImage { FilePath = up.Portfolio.PortfolioImage, Fileupload = up.Fileupload, UserName = username, ObjectType = "Portfolio", ObjectName = up.Portfolio.Name }; string fp = ui.Upload(); // fp will return null if no upload file was choosen else use upload file to save to database if (fp != null) { up.Portfolio.PortfolioImage = fp; } else { up.Portfolio.PortfolioImage = null; } if (!ModelState.IsValid) { up.Privacies = new PrivacyList(); up.User = new User(); up.User.LoadById(userin.Id); up.Privacies.Load(); up.Projects.LoadbyPortfolioID(up.Portfolio.Id); return(View(up)); } up.Portfolio.Update(); return(RedirectToAction("EditPortfolios")); } catch { return(View(up)); } } else { return(RedirectToAction("Index", "Login", new { returnurl = HttpContext.Request.Url })); } }