public void UpdateLatestContact(string userid)
 {
     //update latest contact if entry found
     if (db.JPLatestContacts.Where(c => c.ApplicationUserId == userid).ToList().Count() > 0)
     {
         var contact = db.JPLatestContacts.Where(c => c.ApplicationUserId == userid).FirstOrDefault();
         contact.JPLatestContactDate = DateTime.Now;
         db.SaveChanges();
     }
     //otherwise add new latestContactObject
     else
     {
         var contact = new JPLatestContact();
         contact.ApplicationUserId   = userid;
         contact.JPLatestContactDate = DateTime.Now;
         db.JPLatestContacts.Add(contact);
         db.SaveChanges();
     }
 }
        public ActionResult Create([Bind(Include =
                                             "JPStudentId,JPName,JPEmail,JPStudentLocation,JPStartDate," +
                                             "JPLinkedIn,JPPortfolio,JPGithubLink,JPContact,JPGraduated,JPHired")] JPStudent jPStudent)
        {
            //if (ModelState.IsValid)
            //{
            //    db.JPStudents.Add(jPStudent);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            //return View(jPStudent);

            if (ModelState.IsValid)
            {
                // Test to see if URL provided has http or https in it.
                // If not, then save as is. If it does, strip the protocol.
                string linkedInUrl = jPStudent.JPLinkedIn;
                Regex  regexLI     = new Regex(@"^http(s)?://");
                Match  matchLI     = regexLI.Match(linkedInUrl);
                if (matchLI.Success)
                {
                    Uri    linkedInNewURL = new Uri(linkedInUrl);
                    string linkedInOutput = linkedInNewURL.Host + linkedInNewURL.PathAndQuery;
                    jPStudent.JPLinkedIn = linkedInOutput;
                }
                else
                {
                    jPStudent.JPLinkedIn = linkedInUrl;
                }

                // Test to see if URL provided has http or https in it. If not,
                // then save as is. If it does, strip the protocol.
                string portfolioUrl = jPStudent.JPPortfolio;
                Regex  regexP       = new Regex(@"^http(s)?://");
                Match  matchP       = regexP.Match(portfolioUrl);
                if (matchP.Success)
                {
                    Uri    portfolioNewURL = new Uri(portfolioUrl);
                    string portfolioOutput = portfolioNewURL.Host + portfolioNewURL.PathAndQuery;
                    jPStudent.JPPortfolio = portfolioOutput;
                }
                else
                {
                    jPStudent.JPPortfolio = portfolioUrl;
                }

                JPLatestContact jPLatestContact = new JPLatestContact
                {
                    JPLatestContactDate = DateTime.Now,
                    ApplicationUserId   = User.Identity.GetUserId(),
                    JPLatestContactId   = Guid.NewGuid()
                };

                db.JPLatestContacts.Add(jPLatestContact);


                db.SaveChanges();

                jPStudent.JPStartDate = DateTime.Now;
                jPStudent.JPGraduated = false;
                jPStudent.JPHired     = false;

                jPStudent.ApplicationUserId = User.Identity.GetUserId();
                db.JPStudents.Add(jPStudent);
                db.SaveChanges();

                var checklist = new JPChecklist();
                checklist.ApplicationUserid = User.Identity.GetUserId();
                checklist.JPBusinessCards   = checklist.JPCleanGitHub = checklist.JPMeetups = checklist.JpRoundTables = checklist.JPUpdatedLinkedIn = checklist.JPUpdatedPortfolioSite = false;
                db.JPChecklists.Add(checklist);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(jPStudent));
        }