public ActionResult Create() { ViewBag.Tooltips = toolTips; //Utils.Utility gets the ID of the user that's logged in Utils.Utility userUtil = new Utils.Utility(); int entityID = db.users.Find(userUtil.UserID(User)).entity.ID; //Uses InvestmentViewModel which is at the bottom of this file InvestmentViewModel ivm = new InvestmentViewModel(); //pulling in all the entities in the system ivm.Entities = db.entities.ToList(); //new investment because we're creating one ivm.Investment = new Models.Investment(); //sets the default investment date to the current date ivm.Investment.date = DateTime.Now; //pulling all of the current entity's categories ivm.Categories = new List<Category>(); foreach (var category in db.categories) { if (category.entityID == entityID) { ivm.Categories.Add(category); } } //entityFrom is retrieved based on the user that's logged in ivm.Investment.entityFrom = db.users.Find(userUtil.UserID(User)).entity; //projectsFrom is populated based on entityFrom's projects ivm.Projects = db.projects.Where(i => i.entity.ID == ivm.Investment.entityFrom.ID).ToList(); return View(ivm); }
public ActionResult Edit(int? id) { ViewBag.Tooltips = toolTips; if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } InvestmentViewModel ivm = new InvestmentViewModel(); Utils.Utility userUtil = new Utils.Utility(); ivm.Investment = db.investments.Find(id); ivm.Entities = db.entities.ToList(); ivm.Categories = db.categories.ToList(); ivm.Investment.entityFrom = db.users.Find(userUtil.UserID(User)).entity; ivm.Projects = db.projects.Where(i => i.entity.ID == ivm.Investment.entityFrom.ID).ToList(); ViewBag.InvestmentCategories = string.Join(",", ivm.Investment.categories.Select(c => c.ID)); if (ivm.Investment == null) { return HttpNotFound(); } return View(ivm); }