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);
        }
예제 #2
0
        public ActionResult Index()
        {
            //DashboardViewModel dvm = new DashboardViewModel();
            //Utils.Utility userUtil = new Utils.Utility();
            //var currEntity = db.users.Find(userUtil.UserID(User));
            //dvm.investmentsOut = currEntity.entity.investmentsOut.ToList();
            //dvm.projects = currEntity.entity.projects.ToList();
            //dvm.entity = currEntity.entity;
            //dvm.investment = new Investment();
            //dvm.project = new Project();

            Utils.Utility   uu             = new Utils.Utility();
            List <Category> categoriesList = db.categories.ToList();

            //Redirects to Categories/CreateBase if there are no categories (aka a base category is needed)
            if (categoriesList.Count < 1)
            {
                return(RedirectToAction("CreateBase", "Categories"));
            }
            //Redirects to Dashboard if there is an entity attached to the currently logged in user
            if (db.users.Find(uu.UserID(User)).entity != null)
            {
                var entity = db.users.Find(uu.UserID(User)).entity;
                return(View(entity));
            }
            //If not, redirect to create an entity

            return(RedirectToAction("Create", "Entities"));
        }
        public ActionResult Create([Bind(Include = "ID,name")] Category category, Metric metric, string newMetrics, int baseID)
        {
            if (ModelState.IsValid)
            {
                Utils.Utility userUtil = new Utils.Utility();
                category.entityID = db.users.Find(userUtil.UserID(User)).entity.ID;
                category.isBase   = false;
                category.baseID   = baseID;
                db.categories.Add(category);
                db.SaveChanges();
                var catID = category.ID;

                if (newMetrics != "")
                {
                    foreach (var metricName in newMetrics.Split(','))
                    {
                        metric.name       = metricName;
                        metric.categoryID = catID;
                        db.metrics.Add(metric);
                        db.SaveChanges();
                        Category currentCategory = db.categories.Find(catID);
                        currentCategory.metrics.Add(metric);
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        //For Investments/Edity, gets categories NOT attached to current investment
        public ActionResult NonCurrInvestmentCategories(int investmentID)
        {
            Utils.Utility   userUtil          = new Utils.Utility();
            List <Category> currentCategories = new List <Category>();

            foreach (var category in db.investments.Find(investmentID).categories)
            {
                currentCategories.Add(category);
            }
            List <Category> nonCurrentCategories = new List <Category>();

            foreach (var category in db.categories)
            {
                if (category.entityID == db.users.Find(userUtil.UserID(User)).entity.ID&& !currentCategories.Contains(category))
                {
                    nonCurrentCategories.Add(category);
                }
            }
            var result = JsonConvert.SerializeObject(nonCurrentCategories, Formatting.None,
                                                     new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Content(result, "application/json"));
        }
        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);
        }
예제 #6
0
        public ActionResult Index()
        {
            ViewBag.Tooltips = toolTips;
            Utils.Utility uu     = new Utils.Utility();
            var           entity = db.users.Find(uu.UserID(User)).entity;

            return(View(entity.projects.ToList()));
        }
 public ActionResult Index()
 {
     ViewBag.Tooltips = toolTips;
     //return View(db.investments.ToList());
     Utils.Utility uu = new Utils.Utility();
     var entity = db.users.Find(uu.UserID(User)).entity;
     return View(entity);
 }
        // GET: Map
        public ActionResult Index()
        {
            Utils.Utility userUtil = new Utils.Utility();
            //MapViewModel mvm = new MapViewModel();
            Entity currentEntity = db.users.Find(userUtil.UserID(User)).entity;

            return(View(currentEntity));
        }
예제 #9
0
        public ActionResult GetCurrEntity()
        {
            Utils.Utility userUtil   = new Utils.Utility();
            Entity        currEntity = db.entities.Find(userUtil.UserID(User));
            var           result     = JsonConvert.SerializeObject(currEntity, Formatting.None,
                                                                   new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Content(result, "application/json"));
        }
예제 #10
0
        public ActionResult Create([Bind(Include = "ID,name,description")] Project project)
        {
            if (ModelState.IsValid)
            {
                Utils.Utility userUtil = new Utils.Utility();
                project.entity = db.users.Find(userUtil.UserID(User)).entity;
                db.projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index", "Dashboard"));
            }

            return(View(project));
        }
예제 #11
0
        public ActionResult Create()
        {
            Utils.Utility userUtil = new Utils.Utility();
            User          user     = db.users.Find(userUtil.UserID(User));

            if (user.entity != null)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }
            else
            {
                return(View());
            }
        }
예제 #12
0
        public ActionResult Create([Bind(Include = "ID,name,description,address1,address2,city,state,zip,lat,lng")] Entity entity)
        {
            if (ModelState.IsValid)
            {
                //Instantiating userUtil to get the ID of currently logged in user
                Utils.Utility userUtil = new Utils.Utility();

                //Using geocoder from Google to get latitude and longitude from entity address
                IGeocoder geocoder = new GoogleGeocoder()
                {
                    ApiKey = "AIzaSyDOH51wduQKexTyFXGy0tdDqfXw47XIrjA"
                };
                IEnumerable <Address> addresses = geocoder.Geocode(entity.address1 + " " + entity.address2 + " " + entity.city + " " + entity.state + " " + entity.zip);
                entity.lat = Convert.ToString(addresses.First().Coordinates.Latitude);
                entity.lng = Convert.ToString(addresses.First().Coordinates.Longitude);

                //user is the currently logged in user; attach the entity we're making to the user
                var user = db.users.Find(userUtil.UserID(User));
                db.entities.Add(entity);
                db.SaveChanges();
                user.entity = entity;
                db.SaveChanges();

                //Creating a default project each time that an entity is created
                Project project = new Project();
                project.name        = "General Fund";
                project.description = "General Pool of Funds - unassigned to a project";
                project.entity      = entity;
                db.projects.Add(project);
                db.SaveChanges();
                //Add the project to this entity's list of projects
                entity.projects.Add(project);
                db.SaveChanges();

                //Once the entity is created, redirect to the dashboard IF there are categories in the system
                //If there aren't, that means no base categories exist and the user will be redirected to make one
                List <Category> categoriesList = db.categories.ToList();
                if (categoriesList.Count > 0)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
                else
                {
                    return(RedirectToAction("CreateBase", "Categories"));
                }
            }

            return(View(entity));
        }
        public ActionResult Index()
        {
            Utils.Utility userUtil = new Utils.Utility();
            int           entityID = db.users.Find(userUtil.UserID(User)).entity.ID;

            CategoryViewModel cvm = new CategoryViewModel();

            cvm.UserCategories = new List <Category>();
            //List<Category> userCategories = new List<Category>();
            foreach (var category in db.categories)
            {
                if (category.entityID == entityID)
                {
                    cvm.UserCategories.Add(category);
                }
            }
            cvm.BaseCategories = db.categories.Where(bcat => bcat.isBase == true).ToList();
            //List<Category> categories = db.categories.ToList();
            return(View(cvm));
        }
        public ActionResult UserCategories()
        {
            Utils.Utility   userUtil       = new Utils.Utility();
            List <Category> userCategories = new List <Category>();
            int             currEntityId   = db.users.Find(userUtil.UserID(User)).entity.ID;

            foreach (var category in db.categories)
            {
                if (category.entityID == currEntityId)
                {
                    userCategories.Add(category);
                }
            }
            var result = JsonConvert.SerializeObject(userCategories, Formatting.None,
                                                     new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Content(result, "application/json"));
        }
        public ActionResult Create([Bind(Include = "ID,amount,entityFrom_ID,entityTo_ID,description,date,isInKind, projectFrom_ID,projectTo_ID")] Investment investment, int entityTo_ID, int projectTo_ID, int projectFrom_ID, string categories, string investmentMetrics)
        {
            if (ModelState.IsValid)
            {
                //Utils.Utility gets currently logged in user's ID
                Utils.Utility userUtil = new Utils.Utility();

                //entityTo_ID gets sent in via the forms and then attached to the investment here
                investment.entityTo = db.entities.Find(entityTo_ID);

                //entityFrom uses UserID() from Utils/Utility.cs to get the entity linked to the currently logged in User
                investment.entityFrom = db.users.Find(userUtil.UserID(User)).entity;

                //projectTo_ID and projectFrom_ID get sent in via the forms and then attached to the investment here
                investment.projectTo = db.projects.Find(projectTo_ID);
                investment.projectFrom = db.projects.Find(projectFrom_ID);
                
                //"selectedCategories" is a comma-separated string of categories sent in via the forms 
                //(a hidden input)
                //the string is split into an array, and then each one is added to the new investment's category list
                if (categories != "" && categories != null)
                {
                    investment.categories = new List<Category>();
                    foreach (var id in categories.Split(','))
                    {
                        investment.categories.Add(db.categories.Find(Convert.ToInt32(id)));
                    }
                }

                //"selectedMetrics" is a comma-separated string of categories sent in via the forms 
                //(a hidden input)
                //the string is split into an array, and then each one is added to the new investment's category list
                if (investmentMetrics != "" && investmentMetrics != null)
                {
                    investment.metrics = new List<Metric>();
                    foreach (var id in investmentMetrics.Split(','))
                    {
                        investment.metrics.Add(db.metrics.Find(Convert.ToInt32(id)));
                    }
                }

                //finally we add the investment to the database and save the changes
                db.investments.Add(investment);
                db.SaveChanges();

                //These if statements are analogous to if projectTo != null / if projectFrom != null
                //If the investment has a projectTo, add this investment to that project's investmentsIn list
                if (projectTo_ID != 0)
                {
                    Project newProject = new Project();
                    newProject = db.projects.Find(projectTo_ID);
                    newProject.investmentsIn.Add(db.investments.Find(investment.ID));
                    db.SaveChanges();
                }
                //If the investment has a projectFrom, add this investment to that project's investmentsOut list
                if (projectFrom_ID != 0)
                {
                    Project newProject = new Project();
                    newProject = db.projects.Find(projectFrom_ID);
                    newProject.investmentsOut.Add(db.investments.Find(investment.ID));
                    db.SaveChanges();
                }

                //Now redirect to the dashboard
                return RedirectToAction("Index", "Dashboard");
            }
            return View(investment);
        }