// when user submits login form
        public ActionResult Log_In(LoginViewModel model)
        {
            // search for the users email in the database
            User user = db.Users.FirstOrDefault(c => c.Email == model.LoginEmail);

            // if the user is found
            if (user != null)
            {
                // check to see if passwords match
                if (user.Password == model.LoginPassword)
                {
                    // set the user id and email into session variables
                    Session["UserId"] = user.UserID;
                    Session["UserEmail"] = user.Email;

                    // send user to homepage
                    UserHomeViewModel userHomeModel = new UserHomeViewModel();
                    return View("UserHome", userHomeModel);
                }
                else
                {
                    // return to login screen and notify user of  invalid password
                    model.LoginErrorMessage = "Invalid Password";
                    return View("Index", model);
                }
            }
            else
            {
                // return to login screen and notify user that email was not found
                model.LoginErrorMessage = "Email not found";
                return View("Index", model);
            }
        }
        // when the user submits signup 
        public ActionResult Create_Account(LoginViewModel model)
        {
            // establish connection to database
            CoreysListEntities db = new CoreysListEntities();

            try
            {
                // Checking to see if the email entered already exist in database
                User testUser = db.Users.FirstOrDefault(u => u.Email == model.Email);

                // if not create and add new user
                if (testUser == null)
                {
                    User newUser = new User();
                    newUser.FirstName = model.FirstName;
                    newUser.LastName = model.LastName;
                    newUser.Email = model.Email;
                    newUser.PhoneNum = Convert.ToString(model.PhoneNumber.Replace("-", ""));
                    newUser.Password = model.Password;
                    newUser.CreatedBy = "Corey";
                    newUser.CreatedDate = DateTime.Now;

                    // save the new user to the database
                    db.Users.Add(newUser);
                    db.SaveChanges();

                    // set the new users information in session variables
                    Session["UserId"] = newUser.UserID;
                    Session["UserEmail"] = newUser.Email;

                    // send user to homepage
                    UserHomeViewModel userHomeModel = new UserHomeViewModel();
                    return View("UserHome", userHomeModel);
                }
                else
                {
                    // else return error message informing user that email already is registered
                    model.CreateAccountErrorMessage = "Email already in use";
                    return View("Index", model);
                }
            }  
            catch (Exception e)
            {
                // exception connecting to database
                string error = e.Message;
                return View("Index", model);
            }
        }
 // GET: /Accounts/
 public ActionResult Index()
 {
     // Check to insure user in logged in
     if (Session["UserId"] != null)
     {
         // if so send them to the home page
         UserHomeViewModel userHomeModel = new UserHomeViewModel();
         return View("UserHome", userHomeModel);
     }
     else
     {
         // else send them to login page
         LoginViewModel model = new LoginViewModel();
         return View("Index", model);
     }  
 }
        // Action when homepage is called
        public ActionResult UserHome(int tabId = 0)
        {
            // if user is not logged in return them to login page
            if (Session["UserId"] == null)
            {
                LoginViewModel loginModel = new LoginViewModel();
                return View("Index", loginModel);
            }

            // send them to their home page
            UserHomeViewModel userHomeModel = new UserHomeViewModel();

            // tabId used to keep track of the current Jquery ui tab the user is on
            userHomeModel.TabId = tabId;
            return View("UserHome", userHomeModel);
        }