/// <summary>
        /// Private method that checks to make sure client user is actually related to this account.
        /// </summary>
        /// <returns></returns>
        private EntrepreneurAuth check_clientRelation()
        {
            EntrepreneurAuth cred = new EntrepreneurAuth {
            };

            string[] holding         = Request.RawUrl.Split(new char[] { '/' }).ToArray <string>();
            int      Entrepreneur_Id = 0;

            try
            {
                Entrepreneur_Id = Convert.ToInt32(holding[holding.Count <string>() - 1]);
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("No Entrepreneur Id parameter was passed in.");
                cred.Valid = false;
                return(cred);
            }

            // Get user id from application user id.
            Models.EntrepreneurInitialize authModel = new Models.EntrepreneurInitialize(Entrepreneur_Id, User.Identity.GetUserId());
            cred.Valid           = authModel.valid;
            cred.User_Id         = authModel.User_Id;
            cred.Entrepreneur_ID = authModel.Entrepreneur_ID;
            return(cred);
        }
        public ActionResult Edit()
        {
            EntrepreneurAuth cred = check_clientRelation();

            if (!cred.Valid)
            {
                return(Redirect(@"/User/Index"));
            }
            manageClient_Sessions(cred);
            Models.EntrepreneurEditViewModel entrepreneurAccount = new Models.EntrepreneurEditViewModel(cred.Entrepreneur_ID, User.Identity.GetUserId());
            return(View(entrepreneurAccount));
        }
        public ActionResult createProject()
        {
            EntrepreneurAuth cred = check_clientRelation();

            if (!cred.Valid)
            {
                Redirect("/User/Index"); // kick out of entrepreneur control to the user control.
            }
            manageClient_Sessions(cred);
            Models.EntrepreneurCreateProjectViewModel entrepreneurAccount = new Models.EntrepreneurCreateProjectViewModel(cred.Entrepreneur_ID, User.Identity.GetUserId());
            return(View(entrepreneurAccount));
        }
        public ActionResult Edit(Models.EntrepreneurEditViewModel updateModel, HttpPostedFileBase update_Profile_Image)
        {
            EntrepreneurAuth cred = check_clientRelation();

            if (!cred.Valid)
            {
                return(Redirect("/User/Index"));
            }
            try
            {
                // code to process a posted image file.
                byte[] picture_bytes = null;
                if (ModelState.IsValid)
                {
                    if (update_Profile_Image != null)
                    {
                        if (update_Profile_Image.ContentLength > 0)
                        {
                            int      MaxContentLength      = 1024 * 1024 * 3;
                            string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" };

                            if (!AllowedFileExtensions.Contains(update_Profile_Image.FileName.Substring(update_Profile_Image.FileName.LastIndexOf('.'))))
                            {
                                ModelState.AddModelError("profile_picture", "Please only use file types: " + string.Join(", ", AllowedFileExtensions));
                            }
                            else if (update_Profile_Image.ContentLength > MaxContentLength)
                            {
                                ModelState.AddModelError("profile_picture", string.Format("Your file is too large, maximum file size is: {0} Bytes.", MaxContentLength));
                            }
                            else
                            {
                                picture_bytes = new byte[update_Profile_Image.ContentLength];
                                update_Profile_Image.InputStream.Read(picture_bytes, 0, update_Profile_Image.ContentLength);
                            }
                        }
                    }
                }

                Models.EntrepreneurEditViewModel authModel = new Models.EntrepreneurEditViewModel(cred.Entrepreneur_ID, User.Identity.GetUserId());
                authModel.Name            = updateModel.Name;
                authModel.Profile_Public  = updateModel.Profile_Public;
                authModel.Profile_Picture = picture_bytes;
                authModel.updateEntrepreneur();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(View());
            }
            return(Redirect("/User/Index/"));
        }
        /// <summary>
        /// Private method that manages user client session objects when steping onto pages within this Entrepreneur control.
        /// </summary>
        /// <param name="cred"></param>
        private void manageClient_Sessions(EntrepreneurAuth cred)
        {
            int getSession = 0;

            if (Session["Entrepreneur_ID"] != null)
            {
                getSession = (int)Session["Entrepreneur_ID"];
            }

            if (getSession == 0)
            {
                Session.Add("Entrepreneur_ID", cred.Entrepreneur_ID);
            }
            else
            {
                if (getSession != cred.Entrepreneur_ID)
                {
                    Session["Entrepreneur_ID"] = cred.Entrepreneur_ID;
                }
                // else it is the same and does not need to change
            }
        }
        public ActionResult createProject(Models.EntrepreneurCreateProjectViewModel newProject)
        {
            EntrepreneurAuth cred = check_clientRelation();

            if (!cred.Valid)
            {
                Redirect("/User/Index"); // kick out of entrepreneur control to the user control.
            }
            Models.EntrepreneurCreateProjectViewModel authenticated_newProject = new Models.EntrepreneurCreateProjectViewModel(cred.Entrepreneur_ID, User.Identity.GetUserId());
            authenticated_newProject.Name            = newProject.Name;
            authenticated_newProject.Description     = newProject.Description;
            authenticated_newProject.Investment_Goal = newProject.Investment_Goal;
            int newPRoject_Id = authenticated_newProject.createProject();

            if (newPRoject_Id == 0)
            {
                // TODO: return error to client user on page.
                ModelState.AddModelError("", "Project account not created.");
                return(View(newProject));
            }
            return(Redirect(string.Format("/Project/Index/{0}", newPRoject_Id)));
        }